(function ($) {
    $.fn.yqUiExtText = {
        DialogEditTitle: "Edit",
        DialogEditCol0: "Name",
        DialogEditCol1: "Value",

        DialogMoveTitle: "Move",
        DialogSelectTitle: "Select",

        btnOk: "Ok",
        btnNo: "No",
        btnClose: "Close",

        ComboboxBlankText: "--select--",
        ComboboxBlankText2: "null",
    };

})(jQuery);
/*
UI公共类
*/
jQuery.extend({
    //ui类型
    yqUiTypes: function () {
        return [
            {
                "no": 1,
                "name": "Lable"
            }, {
                "no": 2,
                "name": "Textbox"
            }, {
                "no": 3,
                "name": "Checkbox"
            }, {
                "no": 4,
                "name": "Datetbox"
            }, {
                "no": 5,
                "name": "Richbox"
            }, {
                "no": 6,
                "name": "Combobox"
            }, {
                "no": 7,
                "name": "ForeignKey"
            }, {
                "no": 8,
                "name": "TreeSelect"
            }, {
                "no": 9,
                "name": "Numberbox"
            }, {
                "no": 10,
                "name": "Numberspinner"
            }, {
                "no": 11,
                "name": "TimeSpinner"
            }, {
                "no": 12,
                "name": "DateTimebox"
            }, {
                "no": 13,
                "name": "NCheckBox"
            }, {
                "no": 14,
                "name": "NForeignKey"
            }, {
                "no": 15,
                "name": "Table"
            }, {
                "no": 16,
                "name": "Tree"
            }, {
                "no": 17,
                "name": "Attr"
            }, {
                "no": 18,
                "name": "File"
            }, {
                "no": 19,
                "name": "Html"
            }, {
                "no": 20,
                "name": "SCV"
            }, {
                "no": 21,
                "name": "Func"
            }, {
                "no": 900,
                "name": "ui_type"
            }, {
                "no": 901,
                "name": "titles"
            }
        ];
    },
    yqFmUiTitle: function (title) {
        //console.log("yqFmUiTitle", JSON.stringify($.extend([], title)));
        var newtitle = [];

        for (var ii = 0; ii < title.length; ii++) {
            var col = $.extend({}, title[ii]);
            if (col.ui_title === undefined) {
                col.ui_title = col.name;
            }
            if (col.ui_type === undefined) {
                col.ui_type = 2;
            }
            if (col.ui_width === undefined) {
                col.ui_width = 80;
            }
            if (col.ui_visible === undefined) {
                col.ui_visible = false;
            }
            if (col.ui_readonly === undefined) {
                col.ui_readonly = false;
            }
            if (col.ui_mask === undefined) {
                col.ui_mask = {};
            }

            if (col.is_func === undefined) {
                col.is_func = false;
            }
            else if (col.is_func && col.func === undefined) {
                col.func = "";
            }

            if (typeof col.ui_mask == "string") {
                col.ui_mask = JSON.parse(col.ui_mask);
            }

            col.ui_mask = $.yqUiMaskLoadInit(col.ui_type, col.ui_mask);

            if (col.group === undefined || col.group == "") {
                col.group = "";
            }
            // ,
            //     group:"group1"

            if (col.ui_type == 8) {
                var subfield = col.name;
                var level = col.ui_mask.level;
                while (level > 1) {
                    for (var jj = 0; jj < newtitle.length; jj++) {
                        if (newtitle[jj].ui_type == 8 && subfield == newtitle[jj].ui_mask.subfield) {
                            subfield = newtitle[jj].name;
                            level = newtitle[jj].ui_mask.level;
                            if (level == 1) {
                                col.ui_mask.trees = newtitle[jj].ui_mask.trees;
                            }
                            break;
                        }
                    }
                }
            }

            newtitle.push(col);
        }

        return newtitle;
    },

    //格式化数据表格 columns
    yqDgColumns: function (titles, isEdit) {
        var cols = [];

        if (isEdit === undefined) {
            isEdit = true;
        }

        for (var i = 0; i < titles.length; i++) {
            var title = titles[i];
            if (title.ui_visible) {
                var col = {
                    p_target: this,
                    title: title.ui_title,
                    field: title.name,
                    width: title.ui_width
                };

                if (typeof title.formatter == "function") {
                    col._formatter = title.formatter;
                }

                col.formatter = function (value, row, index) {
                    var _opt = $(this)[0];
                    //console.log("formatter", _opt);
                    var $tdhtml = $.yqPgFormatter.call(this, {
                        value: value,
                        row: row,
                        index: index,
                        field: _opt.field,
                        ui_type: _opt.ui_type,
                        ui_mask: _opt.ui_mask
                    });

                    if (typeof _opt._formatter == "function") {  //自定义
                        $tdhtml = _opt._formatter.call(_opt.p_target, $tdhtml, row, index);
                    }
                    else if (typeof _opt.linkBlank == "function") {   //自定义链接格式
                        $tdhtml = _opt.linkBlank.call(_opt.p_target, $tdhtml, row, index);
                    }

                    return $tdhtml;
                };

                if (typeof title.linkBlank == "function") {
                    col.linkBlank = title.linkBlank;
                }

                if (isEdit && (!(title.ui_readonly || title.is_func))) {
                    col = $.yqDgEditor(col, title.ui_type, title.ui_mask)
                } else {
                    ui_mask = $.yqUiMaskLoadInit(title.ui_type, title.ui_mask);
                    col.ui_type = title.ui_type;
                    col.ui_mask = ui_mask;
                }

                if (title.ui_type == 1) {   //label
                    col.align = "left";
                }
                else if (title.ui_type == 2) {   //textbox
                    col.align = "left";
                }
                else if (title.ui_type == 3) {   //checkbox                   
                    col.align = "center";
                }
                else if (title.ui_type == 4) {   //datebox
                    col.width = Math.max(110, col.width);
                    col.align = "center";
                }
                else if (title.ui_type == 5) {   //richbox
                    col.align = "left";
                }
                else if (title.ui_type == 6) {   //combobox
                    col.align = "center";
                }
                else if (title.ui_type == 7) {   //foreignkey
                    col.align = "left";
                }
                else if (title.ui_type == 8) {   //treeselect
                    col.align = "left";
                }
                else if (title.ui_type == 9) {   //numberbox
                    col.align = "right";
                }
                else if (title.ui_type == 10) {   //numberspinner 
                    col.align = "right";
                }
                else if (title.ui_type == 11) {   //timespinner
                    col.align = "center";
                }
                else if (title.ui_type == 12) {   //datetimebox
                    if (col.width < 127) {
                        col.width = 127;
                    }
                    col.align = "center";
                }
                else if (title.ui_type == 13) {   //NCheckBox
                    col.align = "left";
                }
                else if (title.ui_type == 14) {   //NForeignKey
                    col.align = "left";
                }
                else if (title.ui_type == 15) {   //Table
                    col.align = "left";
                }
                else if (title.ui_type == 16) {   //Tree
                    col.align = "left";
                }
                else if (title.ui_type == 17) {   //Attr
                    col.align = "left";
                }
                else if (title.ui_type == 18) {   //File
                    col.align = "left";
                }
                else if (title.ui_type == 19) {   //Html
                    col.align = "left";
                }
                else if (title.ui_type == 20) {   //SCV
                    col.align = "left";
                }
                else if (title.ui_type == 21) {   //Func
                    col.align = "left";
                }
                else {
                    col.align = "left";
                }

                cols.push(col);
            }
        }

        return [cols];
    },

    //表格编辑设置
    yqDgEditor: function (pp, ui_type, ui_mask) {
        try {
            if (ui_mask === undefined) {
                ui_mask = {};
            }
            ui_mask = $.yqUiMaskLoadInit(ui_type, ui_mask);
            pp.ui_type = ui_type;
            pp.ui_mask = ui_mask;

            var options = {};
            if (ui_type == 2) {
                options = {
                    min: ui_mask.min,
                    max: ui_mask.max,
                    format: ui_mask.format,
                    blank: ui_mask.blank,
                    value: ui_mask.default,
                };
                if (typeof ui_mask.onChange == "function") {
                    options.onChange = ui_mask.onChange;
                }

                options = $.extend({
                    onChange: function (target, value) { }
                }, ui_mask);

                pp.editor = {
                    "type": "dg_textbox",
                    "options": options
                };
            }
            else if (ui_type == 3) {
                options = {
                    checked: ui_mask.default
                };
                if (typeof ui_mask.onChange == "function") {
                    options.onChange = ui_mask.onChange;
                }

                options = $.extend({
                    onChange: function (target, checked) {
                    }
                }, options);

                pp.editor = {
                    type: "dg_checkbox",
                    options: options
                };
            }
            else if (ui_type == 4) {
                options = {
                    min: ui_mask.min,
                    max: ui_mask.max,
                    format: ui_mask.format,
                    blank: ui_mask.blank
                };
                if (typeof ui_mask.onChange == "function") {
                    options.onChange = ui_mask.onChange;
                }

                if (ui_mask.default != null) {
                    options.value = $.convert_todate(ui_mask.default);
                }

                options = $.extend({
                    onChange: function (target, value) { }
                }, options);

                pp.editor = {
                    type: "dg_datebox",
                    options: options
                };
            }
            else if (ui_type == 5) {
                options = {
                    min: ui_mask.min,
                    max: ui_mask.max,
                    blank: ui_mask.blank,
                    value: ui_mask.default
                };

                if (typeof ui_mask.editModeW != "undefined") {
                    options.editModeW = ui_mask.editModeW;
                }
                if (typeof ui_mask.editModeH != "undefined") {
                    options.editModeH = ui_mask.editModeH;
                }
                if (typeof ui_mask.onChange == "function") {
                    options.onChange = ui_mask.onChange;
                }

                options = $.extend({
                    onChange: function (target, value) { }
                }, options);

                pp.editor = {
                    "type": "dg_richbox",
                    "options": options
                };
            }
            else if (ui_type == 6) {
                options = {
                    data: ui_mask.lists,
                    value: ui_mask.default,
                    blank: ui_mask.blank,
                    type: ui_mask.type
                }
                if (typeof ui_mask.onChange == "function") {
                    options.onChange = ui_mask.onChange;
                }

                options = $.extend({
                    onChange: function (target, value) { }
                }, options);

                pp.editor = {
                    type: "dg_combobox",
                    options: options
                };
            }

            else if (ui_type == 7) {
                options = {
                    ajaxUrl: "/_db.html", //ajax地址
                    //width: 200,
                    panelWidth: ui_mask.panelWidth,
                    panelHeight: ui_mask.panelHeight,

                    displayType: ui_mask.displayType,
                    dbname: ui_mask.dbName,
                    tbname: ui_mask.tbName,
                    tempno: ui_mask.tempNo,
                    addWhere: ui_mask.addWhere,
                    order: ui_mask.order,
                    mapping: ui_mask.mapping,

                    defaultValue: ui_mask.default,

                    isPage: ui_mask.isPage,
                    pageSize: ui_mask.pageSize,
                    pageNo: 1,
                    pageList: ui_mask.pageList === undefined ? [5, 10, 20, 30, 40, 50] : ui_mask.pageList,

                    valueMember: ui_mask.valueMember,
                    displayMember: ui_mask.displayMember,

                    titles: [],

                    expandMember: ui_mask.expandMember === undefined ? null : ui_mask.expandMember,
                    isSeek: ui_mask.isSeek,
                    seekNo: ui_mask.seekNo,
                    seekModeW: ui_mask.seekModeW,
                    seekModeH: ui_mask.seekModeH,

                    seekSimple: ui_mask.seekSimple,
                    seekSimpleDDLW: ui_mask.seekSimpleDDLW,
                    seekSimpleTxtW: ui_mask.seekSimpleTxtW,

                    enable: true,
                }
                if (typeof ui_mask.onChange == "function") {
                    options.onChange = ui_mask.onChange;
                }

                options = $.extend(ui_mask, {
                    onChange: function (target, value) { }
                }, options);

                pp.editor = {
                    type: "dg_foreignkey",
                    options: options
                };
            }

            else if (ui_type == 8) {
                if (ui_mask.subfield == "") {
                    ui_mask.subfield = null;
                }

                options = {
                    data: ui_mask.lists,
                    value: ui_mask.default,
                    blank: ui_mask.blank,
                    subfield: ui_mask.subfield,
                    level: ui_mask.level,
                    type: ui_mask.type
                }

                if (ui_mask.level == 1) {
                    options.data = ui_mask.trees;
                }
                else {
                    options.data = [];
                }
                if (typeof ui_mask.onChange == "function") {
                    options.onChange = ui_mask.onChange;
                }

                options = $.extend({
                    onChange: function (target, value) {
                    }
                }, options);

                pp.editor = {
                    type: "dg_combobox_tree",
                    options: options
                };
            }

            else if (ui_type == 9) {
                options = {
                    precision: ui_mask.precision,
                    blank: ui_mask.blank,
                    groupSeparator: ui_mask.groupSeparator
                };

                if (ui_mask.min != null) {
                    options.min = ui_mask.min;
                }
                if (ui_mask.max != null) {
                    options.max = ui_mask.max;
                }
                if (ui_mask.default != null) {
                    options.value = ui_mask.default;
                }
                if (typeof ui_mask.onChange == "function") {
                    options.onChange = ui_mask.onChange;
                }

                options = $.extend({
                    onChange: function (target, value) { }
                }, options);

                pp["editor"] = {
                    "type": "dg_numberbox",
                    "options": options
                };
            }

            else if (ui_type == 10) {
                options = {
                    blank: ui_mask.blank,
                    groupSeparator: ui_mask.groupSeparator
                };

                if (ui_mask.min != null) {
                    options.min = ui_mask.min;
                }
                if (ui_mask.max != null) {
                    options.max = ui_mask.max;
                }
                if (ui_mask.default != null) {
                    options.value = ui_mask.default;
                }
                if (typeof ui_mask.onChange == "function") {
                    options.onChange = ui_mask.onChange;
                }

                options = $.extend({
                    onChange: function (target, value) { }
                }, options);

                pp["editor"] = {
                    "type": "dg_numberspinner",
                    "options": options
                };
            }

            else if (ui_type == 11) {
                options = {
                    blank: ui_mask.blank
                };

                if (ui_mask.min != null) {
                    options.min = ui_mask.min;
                }
                if (ui_mask.max != null) {
                    options.max = ui_mask.max;
                }
                if (ui_mask.seconds != null) {
                    options.showSeconds = ui_mask.seconds;
                }
                if (ui_mask.blank == false) {
                    options.required = true;
                }

                if (ui_mask.default == false) {
                    options.value = ui_mask.default;
                }
                if (typeof ui_mask.onChange == "function") {
                    options.onChange = ui_mask.onChange;
                }

                options = $.extend({
                    onChange: function (target, value) { }
                }, options);

                pp["editor"] = {
                    "type": "dg_timespinner",
                    "options": options
                };
            }

            else if (ui_type == 12) {
                options = {
                    blank: ui_mask.blank,
                    format: ui_mask.format
                };

                if (ui_mask.min != null) {
                    options.min = ui_mask.min;
                }
                if (ui_mask.max != null) {
                    options.max = ui_mask.max;
                }
                if (ui_mask.seconds != null) {
                    options.showSeconds = ui_mask.seconds;
                }

                if (ui_mask.default == false) {
                    options.value = ui_mask.default;
                }
                if (typeof ui_mask.onChange == "function") {
                    options.onChange = ui_mask.onChange;
                }

                options = $.extend({
                    onChange: function (target, value) { }
                }, options);

                pp["editor"] = {
                    "type": "dg_datetimebox",
                    "options": options
                };
            }

            else if (ui_type == 13) {
                options = {
                    lists: ui_mask.lists,
                    blank: ui_mask.blank,
                    value: ui_mask.default,
                    type: ui_mask.type
                };
                if (typeof ui_mask.onChange == "object") {
                    options.onChange = ui_mask.onChange;
                }

                if (typeof ui_mask.editModeW != "undefined") {
                    options.editModeW = ui_mask.editModeW;
                }
                if (typeof ui_mask.editModeH != "undefined") {
                    options.editModeH = ui_mask.editModeH;
                }
                if (typeof ui_mask.onChange == "function") {
                    options.onChange = ui_mask.onChange;
                }

                options = $.extend({
                    onChange: function (target, value) { }
                }, options);

                pp.editor = {
                    "type": "dg_ncombobox",
                    "options": options
                };
            }

            else if (ui_type == 14) {
                options = {
                    ajaxUrl: "/_db.html", //ajax地址
                    //width: 200,
                    panelWidth: ui_mask.panelWidth,
                    panelHeight: ui_mask.panelHeight,

                    dbname: ui_mask.dbName,
                    tbname: ui_mask.tbName,
                    tempno: ui_mask.tempNo,
                    addWhere: ui_mask.addWhere,
                    order: ui_mask.order,
                    mapping: ui_mask.mapping,

                    defaultValue: ui_mask.default,

                    isPage: ui_mask.isPage,
                    pageSize: ui_mask.pageSize,
                    pageNo: 1,
                    pageList: ui_mask.pageList === undefined ? [5, 10, 20, 30, 40, 50] : ui_mask.pageList,

                    valueMember: ui_mask.valueMember,
                    displayMember: ui_mask.displayMember,

                    titles: [],

                    expandMember: ui_mask.expandMember === undefined ? null : ui_mask.expandMember,
                    isSeek: ui_mask.isSeek,
                    seekNo: ui_mask.seekNo,
                    seekModeW: ui_mask.seekModeW,
                    seekModeH: ui_mask.seekModeH,

                    seekSimple: ui_mask.seekSimple,
                    seekSimpleDDLW: ui_mask.seekSimpleDDLW,
                    seekSimpleTxtW: ui_mask.seekSimpleTxtW,

                    enable: true,
                }
                if (typeof ui_mask.onChange == "function") {
                    options.onChange = ui_mask.onChange;
                }

                options = $.extend({
                    onChange: function (target, value) { }
                }, options);

                pp.editor = {
                    type: "dg_nforeignkey",
                    options: options
                };
            }

            else if (ui_type == 15) {
                options = {
                    blank: ui_mask.blank
                };

                if (!(ui_mask.param.titles === undefined)) {
                    options.titles = ui_mask.param.titles;
                }
                if (!(ui_mask.editModeW === undefined)) {
                    options.editModeW = ui_mask.editModeW;
                }
                if (!(ui_mask.editModeH === undefined)) {
                    options.editModeH = ui_mask.editModeH;
                }
                if (!(typeof ui_mask.isEdit === undefined)) {
                    options.isEdit = ui_mask.isEdit;
                }
                if (!(typeof ui_mask.isAdd === undefined)) {
                    options.isAdd = ui_mask.isAdd;
                }
                if (!(typeof ui_mask.isDel === undefined)) {
                    options.isDel = ui_mask.isDel;
                }
                if (!(typeof ui_mask.isMove === undefined)) {
                    options.isMove = ui_mask.isMove;
                }

                if (!(typeof ui_mask.toexcel === undefined)) {
                    options.toexcel = ui_mask.toexcel;
                }
                if (!(typeof ui_mask.excelName === undefined)) {
                    options.excelName = ui_mask.excelName;
                }
                if (!(typeof ui_mask.inexcel === undefined)) {
                    options.inexcel = ui_mask.inexcel;
                }

                if (!(typeof ui_mask.frozenNum === undefined)) {
                    options.frozenNum = ui_mask.frozenNum;
                }
                if (!(typeof ui_mask.rownumbers === undefined)) {
                    options.rownumbers = ui_mask.rownumbers;
                }
                if (!(typeof ui_mask.sumList === undefined)) {
                    options.sumList = ui_mask.sumList;
                }

                if (ui_mask.beforeBindingTitle) {
                    options.beforeBindingTitle = ui_mask.beforeBindingTitle;
                }
                if (ui_mask.afterBindingTitle) {
                    options.afterBindingTitle = ui_mask.afterBindingTitle;
                }
                if (ui_mask.beforeEditShow) {
                    options.beforeEditShow = ui_mask.beforeEditShow;
                }
                if (ui_mask.beforeEditShow) {
                    options.beforeEditShow = ui_mask.beforeEditShow;
                }
                if (ui_mask.beforeAdd) {
                    options.beforeAdd = ui_mask.beforeAdd;
                }
                if (ui_mask.afterChange) {
                    options.afterChange = ui_mask.afterChange;
                }

                options = $.extend({
                    onChange: function (target, value) {
                    }
                }, options);

                pp["editor"] = {
                    "type": "dg_texttable",
                    "options": options
                };
            }

            else if (ui_type == 16) {
                options = {
                    blank: ui_mask.blank
                };

                if (!(ui_mask.displayMember)) {
                    options.displayMember = ui_mask.displayMember;
                }
                if (!(ui_mask.param.titles === undefined)) {
                    options.titles = ui_mask.param.titles;
                }
                if (!(typeof ui_mask.editModeW === undefined)) {
                    options.editModeW = ui_mask.editModeW;
                }
                if (!(typeof ui_mask.editModeH === undefined)) {
                    options.editModeH = ui_mask.editModeH;
                }
                if (!(typeof ui_mask.isEdit === undefined)) {
                    options.isEdit = ui_mask.isEdit;
                }
                if (!(typeof ui_mask.isAdd === undefined)) {
                    options.isAdd = ui_mask.isAdd;
                }
                if (!(typeof ui_mask.isDel === undefined)) {
                    options.isDel = ui_mask.isDel;
                }

                if (ui_mask.beforeBindingTitle) {
                    options.beforeBindingTitle = ui_mask.beforeBindingTitle;
                }
                if (ui_mask.afterBindingTitle) {
                    options.afterBindingTitle = ui_mask.afterBindingTitle;
                }
                if (ui_mask.beforeAdd) {
                    options.beforeAdd = ui_mask.beforeAdd;
                }
                if (ui_mask.beforeEditShow) {
                    options.beforeEditShow = ui_mask.beforeEditShow;
                }
                if (ui_mask.beforeChange) {
                    options.beforeChange = ui_mask.beforeChange;
                }
                if (ui_mask.afterChange) {
                    options.afterChange = ui_mask.afterChange;
                }

                options = $.extend({
                    onChange: function (target, value) {
                    }
                }, options);

                pp["editor"] = {
                    "type": "dg_texttree",
                    "options": options
                };
            }

            else if (ui_type == 17) {
                options = {
                    loadDefault: true,
                    blank: ui_mask.blank
                };
                if (!(ui_mask.param.titles === undefined)) {
                    options.titles = ui_mask.param.titles;
                }
                if (!(ui_mask.param.model === undefined)) {
                    options.model = ui_mask.param.model;
                }
                if (!(ui_mask.editModeW === undefined)) {
                    options.editModeW = ui_mask.editModeW;
                }
                if (!(ui_mask.editModeH === undefined)) {
                    options.editModeH = ui_mask.editModeH;
                }
                if (!(ui_mask.editType === undefined)) {
                    options.editType = ui_mask.editType;
                }
                if (!(ui_mask.removeUnUse === undefined)) {
                    options.removeUnUse = ui_mask.removeUnUse;
                }

                if (ui_mask.beforeBindingTitle) {
                    options.beforeBindingTitle = ui_mask.beforeBindingTitle;
                }
                if (ui_mask.afterBindingTitle) {
                    options.afterBindingTitle = ui_mask.afterBindingTitle;
                }
                if (ui_mask.beforeEditShow) {
                    options.beforeEditShow = ui_mask.beforeEditShow;
                }
                if (ui_mask.beforeChange) {
                    options.beforeChange = ui_mask.beforeChange;
                }
                if (ui_mask.afterChange) {
                    options.afterChange = ui_mask.afterChange;
                }
                if (ui_mask.onChange) {
                    options.onChange = ui_mask.onChange;
                }
                options = $.extend({
                    onChange: function (target, value) {

                    }
                }, options);

                pp["editor"] = {
                    "type": "dg_textattr",
                    "options": options
                };
            }

            else if (ui_type == 18) {
                ui_mask = $.extend({
                    onChange: function (target, value) { }
                }, ui_mask);

                pp["editor"] = {
                    "type": "dg_filebox",
                    "options": ui_mask
                };
            }

            else if (ui_type == 19) {
                ui_mask.editType = ui_mask.type;

                ui_mask = $.extend({
                    onChange: function (target, value) { }
                }, ui_mask);

                pp["editor"] = {
                    "type": "dg_richedit",
                    "options": ui_mask
                };
            }

            else if (ui_type == 20) {
                options = {
                    blank: ui_mask.blank
                };

                if (!(ui_mask.ui_type === undefined)) {
                    options.ui_type = ui_mask.ui_type;
                }
                if (!(ui_mask.ui_mask === undefined)) {
                    options.ui_mask = ui_mask.ui_mask;
                }
                if (!(ui_mask.separator === undefined)) {
                    options.separator = ui_mask.separator;
                }
                if (!(typeof ui_mask.isEdit === undefined)) {
                    options.isEdit = ui_mask.isEdit;
                }
                if (!(typeof ui_mask.isAdd === undefined)) {
                    options.isAdd = ui_mask.isAdd;
                }
                if (!(typeof ui_mask.isDel === undefined)) {
                    options.isDel = ui_mask.isDel;
                }
                if (!(typeof ui_mask.isMove === undefined)) {
                    options.isMove = ui_mask.isMove;
                }
                if (!(ui_mask.editModeW === undefined)) {
                    options.editModeW = ui_mask.editModeW;
                }
                if (!(ui_mask.editModeH === undefined)) {
                    options.editModeH = ui_mask.editModeH;
                }

                if (ui_mask.beforeBindingTitle) {
                    options.beforeBindingTitle = ui_mask.beforeBindingTitle;
                }
                if (ui_mask.afterBindingTitle) {
                    options.afterBindingTitle = ui_mask.afterBindingTitle;
                }
                if (ui_mask.beforeEditShow) {
                    options.beforeEditShow = ui_mask.beforeEditShow;
                }
                if (ui_mask.beforeEditShow) {
                    options.beforeEditShow = ui_mask.beforeEditShow;
                }
                if (ui_mask.beforeAdd) {
                    options.beforeAdd = ui_mask.beforeAdd;
                }
                if (ui_mask.afterChange) {
                    options.afterChange = ui_mask.afterChange;
                }

                options = $.extend({
                    onChange: function (target, value) { }
                }, options);

                pp["editor"] = {
                    "type": "dg_textcsv",
                    "options": options
                };
            }

            else if (ui_type == 21) {
                options = {
                    blank: ui_mask.blank
                };

                if (!(typeof ui_mask.isEdit === undefined)) {
                    options.isEdit = ui_mask.isEdit;
                }

                if (ui_mask.beforeBindingTitle) {
                    options.beforeBindingTitle = ui_mask.beforeBindingTitle;
                }
                if (ui_mask.afterBindingTitle) {
                    options.afterBindingTitle = ui_mask.afterBindingTitle;
                }
                if (ui_mask.funcCallback) {
                    options.funcCallback = ui_mask.funcCallback;
                }
                if (ui_mask.afterChange) {
                    options.afterChange = ui_mask.afterChange;
                }
                if (ui_mask.beforeClear) {
                    options.beforeClear = ui_mask.beforeClear;
                }

                options = $.extend({
                    onChange: function (target, value) { }
                }, options);

                pp["editor"] = {
                    "type": "dg_textfunc",
                    "options": options
                };
            }
            else if (ui_type == 900) {
                if (ui_mask.pop_edit) {
                    ui_mask = $.extend({
                        onChange: function (target, rows) {

                        }
                    }, ui_mask);

                    pp["editor"] = {
                        "type": "dg_ui_mask",
                        "options": ui_mask
                    };
                }
            }
            else if (ui_type == 901) {
                ui_mask = $.extend({
                    onChange: function (target, value) {
                        // console.log($(this), target);
                        // console.log("newValue:" + value);
                    }
                }, ui_mask);

                pp["editor"] = {
                    "type": "dg_titlesedit",
                    "options": ui_mask
                };
            }
        } catch (error) {

        }

        return pp;
    },

    //表格显示设置
    /*
    var para = {
            value: "",
            row: {},
            index: 1,
            ui_name: "",
            ui_type: 1,
            ui_mask: {}
        }

    */
    yqPgFormatter: function (para, fromCol) {
        //console.log($(this),para);

        // if (typeof para.row.ui_mask != "undefined" && fromCol === undefined) {
        //     para.ui_type = para.row.ui_type;
        //     para.ui_mask = para.row.ui_mask;
        // }

        if (para.value === undefined) {
            para.value = null;
        }

        var b_value = para.value;

        if (para.ui_type == 3) {
            if (para.row["_footer_"] === undefined) { //_footer_ 有汇总标记
                if (para.value) {
                    b_value = '<input type="checkbox" disabled="disabled" checked/>';
                } else {
                    b_value = '<input type="checkbox" disabled="disabled" \/>';
                }
            } else {
                b_value = "";
            }
        }
        else if (para.ui_type == 4) {
            return $.formatterdatebox(para.value, para.ui_mask.format);
        }

        else if (para.ui_type == 6) {
            //console.log(para);
            var b_value = "";
            if (!(para.value === undefined ||
                para.value === null ||
                para.value === -1 ||
                para.value === "")) {
                for (let i = 0; i < para.ui_mask.lists.length; i++) {
                    var ck_val = para.ui_mask.lists[i]["no"];
                    if (para.ui_mask.type == "string") {
                        if (typeof ck_val != "string") {
                            ck_val = ck_val.toString();
                        }
                    } else {
                        ck_val = $.yqToInt(ck_val);
                    }
                    if (para.value === ck_val) {
                        b_value = para.ui_mask.lists[i]["name"];
                        break;
                    }
                }
            }

            return b_value;
        }

        else if (para.ui_type == 7) {
            b_value = "";
            var p_opt;
            try {
                var yqtype = this.p_target.data("yqtype");
                if (yqtype == "yqDataGrid" ||
                    yqtype == "yqComboGrid" ||
                    yqtype == "yqForeignKey" ||
                    yqtype == "yqTableEdit" ||
                    yqtype == "yqTreeEdit" ||
                    yqtype == "datagrid") {
                    if (yqtype == "yqDataGrid") {
                        p_opt = this.p_target.yqDataGrid("options");
                    } else if (yqtype == "yqComboGrid") {
                        p_opt = this.p_target.yqComboGrid("options");
                    } else if (yqtype == "yqForeignKey") {
                        p_opt = this.p_target.yqForeignKey("options");
                    }
                    else if (yqtype == "yqTableEdit") {
                        p_opt = this.p_target.yqTableEdit("options");
                    }
                    else if (yqtype == "yqTreeEdit") {
                        p_opt = this.p_target.yqTreeEdit("options");
                    }
                    else if (yqtype == "datagrid") {
                        p_opt = this.p_target.options.prevent_e.options;
                    }

                    if (!(para.value === null || para.value === "")) {
                        for (let i = 0; i < p_opt.fk_rows.length; i++) {
                            if (p_opt.fk_rows[i].field == para.field) {
                                for (let j = 0; j < p_opt.fk_rows[i].rows.length; j++) {
                                    if (p_opt.fk_rows[i].rows[j][para.ui_mask.valueMember] == para.value) {
                                        b_value = $.getDisplayValue(p_opt.fk_rows[i].rows[j], para.ui_mask.displayMember);
                                        break;
                                    }
                                }

                                break;
                            }
                        }
                    }
                } else if (yqtype == "yqAttrEdit" || yqtype == "yqUiMaskEdit") {
                    if (yqtype == "yqAttrEdit") {
                        p_opt = this.p_target.yqAttrEdit("options");
                    } else if (yqtype == "yqUiMaskEdit") {
                        p_opt = this.p_target.yqUiMaskEdit("options");
                    }

                    if (!(para.value === null || para.value === "")) {
                        for (let i = 0; i < p_opt.fk_rows.length; i++) {
                            if (p_opt.fk_rows[i].field == para.row.field) {
                                for (let j = 0; j < p_opt.fk_rows[i].rows.length; j++) {
                                    if (p_opt.fk_rows[i].rows[j][para.ui_mask.valueMember] == para.row.value) {
                                        b_value = $.getDisplayValue(p_opt.fk_rows[i].rows[j], para.row.ui_mask.displayMember);
                                        break;
                                    }
                                }

                                break;
                            }
                        }
                    }
                }
            } catch (error) {
                console.log(error);
            }
        }

        else if (para.ui_type == 8) {
            b_value = "";
            if (!(para.value === undefined ||
                para.value === null ||
                para.value === -1 ||
                para.value === "")) {
                b_value = get_fk_val(1, para.ui_mask.trees);
            }

            function get_fk_val(level, trees) {
                if (typeof trees != "object") {
                    return "";
                }

                for (var l = 0; l < trees.length; l++) {
                    if (level < para.ui_mask.level) {
                        var tval = get_fk_val(level + 1, trees[l].subs);
                        if (tval.toString() != "") {
                            return tval;
                        }
                    }
                    else if (level == para.ui_mask.level) {
                        var ck_val = trees[l].no;
                        if (para.ui_mask.type == "string") {
                            if (typeof ck_val != "string") {
                                ck_val = ck_val.toString();
                            }
                        } else {
                            ck_val = $.yqToInt(ck_val);
                        }

                        if (ck_val == para.value) {
                            return trees[l].name;
                            break;
                        }
                    }
                }

                return "";
            }
        }

        else if (para.ui_type == 9) {
            return $.formatternumberbox(para.value, para.ui_mask);
        }
        else if (para.ui_type == 10) {
            return $.formatternumberspinner(para.value, para.ui_mask);
        }

        else if (para.ui_type == 12) {
            return $.formatterdatetimebox(para.value, para.ui_mask.format);
        }

        else if (para.ui_type == 13) {
            var b_value = "";
            if (!(para.value === undefined ||
                para.value === null ||
                para.value == -1 ||
                para.value == "")) {
                for (let i = 0; i < para.ui_mask.lists.length; i++) {
                    if (("," + para.value + ",").indexOf("," + para.ui_mask.lists[i]["no"] + ",") != -1) {
                        b_value += (b_value == "" ? "" : ",") + para.ui_mask.lists[i]["name"];
                    }
                }
            }
            return b_value;
        }

        else if (para.ui_type == 14) {
            b_value = "";
            try {
                var p_opt;
                var yqtype = this.p_target.data("yqtype");
                if (yqtype == "yqDataGrid" ||
                    yqtype == "yqComboGrid" ||
                    yqtype == "yqForeignKey" ||
                    yqtype == "yqTableEdit" ||
                    yqtype == "yqTreeEdit" ||
                    yqtype == "datagrid") {
                    if (yqtype == "yqDataGrid") {
                        p_opt = this.p_target.yqDataGrid("options");
                    } else if (yqtype == "yqComboGrid") {
                        p_opt = this.p_target.yqComboGrid("options");
                    } else if (yqtype == "yqForeignKey") {
                        p_opt = this.p_target.yqForeignKey("options");
                    }
                    else if (yqtype == "yqTableEdit") {
                        p_opt = this.p_target.yqTableEdit("options");
                    }
                    else if (yqtype == "yqTreeEdit") {
                        p_opt = this.p_target.yqTreeEdit("options");
                    }
                    else if (yqtype == "datagrid") {
                        p_opt = this.p_target.options.prevent_e.options;
                    }

                    if (!(para.value === null || para.value === "")) {
                        var _s = para.value.split(",");
                        for (var s_i = 0; s_i < _s.length; s_i++) {
                            var _v = _s[s_i];
                            for (var i = 0; i < p_opt.fk_rows.length; i++) {
                                if (p_opt.fk_rows[i].field == para.field) {
                                    for (var j = 0; j < p_opt.fk_rows[i].rows.length; j++) {
                                        if (p_opt.fk_rows[i].rows[j][para.ui_mask.valueMember] == _v) {
                                            b_value += (b_value == "" ? "" : ",") + $.getDisplayValue(p_opt.fk_rows[i].rows[j], para.ui_mask.displayMember);
                                            break;
                                        }
                                    }

                                    break;
                                }
                            }
                        }
                    }
                } else if (yqtype == "yqAttrEdit" || yqtype == "yqUiMaskEdit") {
                    if (yqtype == "yqAttrEdit") {
                        p_opt = this.p_target.yqAttrEdit("options");
                    } else if (yqtype == "yqUiMaskEdit") {
                        p_opt = this.p_target.yqUiMaskEdit("options");
                    }

                    if (!(para.value === null || para.value === "")) {
                        var _s = para.value.split(",");
                        for (var s_i = 0; s_i < _s.length; s_i++) {
                            var _v = _s[s_i];
                            for (var i = 0; i < p_opt.fk_rows.length; i++) {
                                if (p_opt.fk_rows[i].field == para.row.field) {
                                    for (var j = 0; j < p_opt.fk_rows[i].rows.length; j++) {
                                        if (p_opt.fk_rows[i].rows[j][para.ui_mask.valueMember] == _v) {
                                            b_value += (b_value == "" ? "" : ",") + $.getDisplayValue(p_opt.fk_rows[i].rows[j], para.ui_mask.displayMember);
                                            break;
                                        }
                                    }

                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch (error) {
                console.log(error);
            }
        }

        else if (para.ui_type == 15 || para.ui_type == 16 || para.ui_type == 17) {
            if (para.value === null) {
                return "";
            }
            else if (typeof para.value == "object") {
                return JSON.stringify(para.value);
            }
            else if (typeof para.value == "string") {
                return para.value;
            } else {
                return "";
            }
        }

        else if (para.ui_type == 18) { //file 
            if (typeof b_value == "string") {
                b_value = JSON.parse(b_value);
            }
            else if (typeof b_value != "object") {
                b_value = null;
            }

            if (b_value === null) {
                return "";
            } else {
                return b_value.name;
            }
        }

        else if (para.ui_type == 19) { //html markdown
            if (typeof b_value == "string") {
                b_value = JSON.parse(b_value);
            }
            else if (typeof b_value != "object") {
                b_value = null;
            }

            if (b_value === null) {
                return "";
            } else {
                if (para.ui_mask.type == 1) {
                    var $html = $("<div>" + b_value.html + "</div>");
                    b_value = $html.text();
                    if (b_value == "") {
                        b_value = "..."
                    }
                    return b_value;
                } else if (para.ui_mask.type == 2) {
                    b_value = b_value.code;
                    if (b_value == "") {
                        b_value = "..."
                    }
                    return b_value;
                }
            }
        }
        else if (para.ui_type == 20) { //csv
            if (Object.prototype.toString.call(b_value) === '[object Array]') {
                val = "";
                for (var i = 0; i < b_value.length; i++) {
                    if (i > 0) {
                        val += para.ui_mask.separator;
                    }
                    val += b_value[i];
                }
                b_value = val;
            }

            if (b_value === null) {
                b_value = "";
            }
        }
        else if (para.ui_type == 900) { //ui_mask
            if (typeof b_value == "string") {
                b_value = JSON.parse(b_value);
            }
            else if (typeof b_value != "object") {
                b_value = null;
            }

            if (b_value === null) {
                return "";
            } else {
                return JSON.stringify(b_value);
            }
        }
        else if (para.ui_type == 901) { //titles
            return '' + JSON.stringify({ titles: para.value.titles });
        }

        return b_value;
    },

    //加载ui前格式化
    yqUiMaskLoadInit: function (ui_type, ui_mask) {
        try {
            if(ui_mask === null){
                ui_mask = {};
            }else if (typeof ui_mask === "string") {
                ui_mask = JSON.parse(ui_mask);
            }
        } catch (error) {
            console.log("yqUiMaskLoadInit,pos[0]", error);
            console.log("ui_type", ui_type);
            console.log("ui_mask", ui_mask);
            ui_mask = {};
        }

        var _ui_mask = {};
        if (ui_type == 1) {  //lable
            _ui_mask = $.extend({
                default: null
            }, ui_mask);
        } else if (ui_type == 2) {  //textbox
            _ui_mask = $.extend({
                default: null,
                blank: true,
                min: null,
                max: null,
                format: "",
                onChange: function (target, value) {
                    //console.log($(this),target,value);
                }
            }, ui_mask);
        } else if (ui_type == 3) {  //checkbox
            _ui_mask = $.extend({
                default: false,
                onChange: function (target, value) {
                    //console.log($(this),target,value);
                }
            }, ui_mask);
        } else if (ui_type == 4) {//datebox
            _ui_mask = $.extend({
                default: null,
                blank: true,
                min: null,
                max: null,
                format: "yyyy/MM/dd",
                onChange: function (target, value) {
                    //console.log($(this),target,value);
                }
            }, ui_mask);
        } else if (ui_type == 5) {  //richbox
            _ui_mask = $.extend({
                default: $.yqUiMask5_types[0].name,
                types: [$.yqUiMask5_types[0].name],
                blank: true,
                min: null,
                max: null,
                editModeW: 400, //模态编辑器宽度 格式为 400（数字）
                editModeH: 300, //模态编辑器高度 格式为 300（数字）
                onChange: function (target, value) {
                    //console.log($(this),target,value);
                }
            }, ui_mask);
        } else if (ui_type == 6) { //combobox
            if (typeof ui_mask.lists == "string") {
                ui_mask.lists = JSON.parse(ui_mask.lists);
            }

            _ui_mask = $.extend({
                default: "-1",
                blank: true,
                type: "int",     //值类型 int、string
                lists: [],
                onChange: function (target, value) {
                    //console.log($(this),target,value);
                }
            }, ui_mask);
        } else if (ui_type == 7) {//foreignkey
            if (typeof ui_mask.mapping == "string") {
                ui_mask.mapping = JSON.parse(ui_mask.mapping);
            }
            _ui_mask = $.extend({
                default: null,
                blank: true,
                dbName: "",
                tbName: "",
                tempNo: -1,
                displayType: 2,
                valueMember: "sid",
                displayMember: "sid",
                isPage: true,
                pageSize: 10,
                addWhere: "",
                order: "sid",
                mapping: [],

                panelWidth: 400,
                panelHeight: 260,
                expandMember: null,

                seekSimple: true,     //简单查询
                seekSimpleDDLW: 120,  //条件宽度
                seekSimpleTxtW: 150,  //条件宽度

                isSeek: true,
                seekNo: -1,
                seekModeW: 800,
                seekModeH: 600,
                onChange: function (target, value) {
                    //var opts = $(this).yqForeignKey("options");
                    //console.log(opts.p_target, target, value);
                }
            }, ui_mask);
        } else if (ui_type == 8) {//treeselect
            if (typeof ui_mask.trees == "string") {
                ui_mask.trees = JSON.parse(ui_mask.trees);
            }

            _ui_mask = $.extend({
                default: [],
                blank: true,
                level: 1,
                subfield: "",
                type: "int",     //值类型 int、string
                trees: [],
                onChange: function (target, value) {
                    //console.log($(this),target,value);
                }
            }, ui_mask);
        } else if (ui_type == 9) { //NumberBox
            _ui_mask = $.extend({
                default: null,
                blank: true,
                min: null,
                max: null,
                precision: 0,
                groupSeparator: "",
                onChange: function (target, value) {
                    //console.log($(this),target,value);
                }
            }, ui_mask);
        } else if (ui_type == 10) { //NumberSpinner
            _ui_mask = $.extend({
                default: null,
                blank: true,
                min: null,
                max: null,
                groupSeparator: "",
                onChange: function (target, value) {
                    //console.log($(this),target,value);
                }
            }, ui_mask);
        } else if (ui_type == 11) { //TimeSpinner
            _ui_mask = $.extend({
                default: null,
                min: null,
                max: null,
                blank: true,
                seconds: false,
                onChange: function (target, value) {
                    //console.log($(this),target,value);
                }
            }, ui_mask);
        } else if (ui_type == 12) { //DateTimeBox
            _ui_mask = $.extend({
                default: null,
                min: null,
                max: null,
                blank: true,
                seconds: false,
                format: "yyyy/MM/dd HH:mm",
                onChange: function (target, value) {
                    //console.log($(this),target,value);
                }
            }, ui_mask);
        } else if (ui_type == 13) {//NCombobox 多选 
            if (typeof ui_mask.lists == "string") {
                ui_mask.lists = JSON.parse(ui_mask.lists);
            }
            _ui_mask = $.extend({
                default: null,
                blank: true,
                type: "int",     //值类型 int、string
                lists: [],
                editModeW: 400, //模态编辑器宽度 格式为 800（数字）
                editModeH: 300, //模态编辑器高度 格式为 600（数字）
                onChange: function (target, value) {
                    //console.log($(this),target,value);
                }
            }, ui_mask);

            for (var i = 0; i < _ui_mask.lists.length; i++) {
                if (("," + _ui_mask.default + ",").indexOf("," + _ui_mask.lists[i].no + ",") == -1) {
                    _ui_mask.lists[i].checked = false;
                } else {
                    _ui_mask.lists[i].checked = true;
                }
            }
        } else if (ui_type == 14) {//NForeignKey 多选外键
            _ui_mask = $.extend({
                default: null,
                blank: true,
                dbName: "",
                tbName: "",
                tempNo: -1,
                displayType: 2,
                valueMember: "sid",
                displayMember: "sid",
                isPage: true,
                pageSize: 10,
                addWhere: "",
                order: "sid",
                mapping: [],

                panelWidth: 400,
                panelHeight: 260,
                expandMember: null,

                seekSimple: true,     //简单查询
                seekSimpleDDLW: 120,  //条件宽度
                seekSimpleTxtW: 150,  //条件宽度

                isSeek: true,
                seekNo: -1,
                seekModeW: 800,
                seekModeH: 600,
                onChange: function (target, value) {
                    //console.log($(this),target,value);
                }
            }, ui_mask);
        } else if (ui_type == 15) {//TbEdit 表格数据
            if (typeof ui_mask.param == "string") {
                ui_mask.param = JSON.parse(ui_mask.param);
            }
            if (typeof ui_mask.rows == "string") {
                rows.rows = JSON.parse(ui_mask.rows);
            }

            _ui_mask = $.extend({
                blank: true,
                editModeW: 450,
                editModeH: 450,
                editType: 0,
                modelNo: -1,
                panelWidth: 500,
                panelHeight: 400,
                param: {
                    titles: [
                        {
                            name: "no",
                            ui_title: "No",
                            ui_type: 2,
                            ui_width: 90,
                            ui_visible: true,
                            ui_readonly: false,
                            ui_mask: {}
                        }, {
                            name: "name",
                            ui_title: "Name",
                            ui_type: 2,
                            ui_width: 150,
                            ui_visible: true,
                            ui_readonly: false,
                            ui_mask: {}
                        }
                    ],
                    model: []
                },
                rows: [],
                onChange: function (target, value) {
                    //console.log($(this), target, value);
                }
            }, ui_mask);
        } else if (ui_type == 16) { //tree 数据
            if (typeof ui_mask.param == "string") {
                ui_mask.param = JSON.parse(ui_mask.param);
            }
            if (typeof ui_mask.data == "string") {
                ui_mask.data = JSON.parse(ui_mask.data);
            }

            _ui_mask = $.extend({
                blank: true,
                displayMember: "name",
                param: {
                    titles: [
                        {
                            name: "no",
                            ui_title: "No",
                            ui_type: 2,
                            ui_width: 90,
                            ui_visible: true,
                            ui_readonly: false,
                            ui_mask: {}
                        }, {
                            name: "name",
                            ui_title: "Name",
                            ui_type: 2,
                            ui_width: 150,
                            ui_visible: true,
                            ui_readonly: false,
                            ui_mask: {}
                        }
                    ],
                    model: []
                },
                data: [],
                editModeW: 450,
                editModeH: 450,
                editType: 0,
                modelNo: -1,
                panelWidth: 500,
                panelHeight: 400,
                onChange: function (target, value) {
                    //console.log($(this), target, value);
                }
            }, ui_mask);
        } else if (ui_type == 17) {//attr 属性数据
            if (typeof ui_mask.param == "string") {
                ui_mask.param = JSON.parse(ui_mask.param);
            }
            if (typeof ui_mask.default == "string") {
                ui_mask.default = JSON.parse(ui_mask.default);
            }

            _ui_mask = $.extend({
                default: {},
                param: {
                    titles: [
                        {
                            name: "no",
                            ui_title: "No",
                            ui_type: 2,
                            ui_width: 90,
                            ui_visible: true,
                            ui_readonly: false,
                            ui_mask: {}
                        }, {
                            name: "name",
                            ui_title: "Name",
                            ui_type: 2,
                            ui_width: 150,
                            ui_visible: true,
                            ui_readonly: false,
                            ui_mask: {}
                        }
                    ],
                    model: []
                },
                editType: 1,
                editModeW: 450,
                editModeH: 400,
                modeNo: -1,
                onChange: function (target, value) {
                    //console.log($(this), target, value);
                }
            }, ui_mask);
        } else if (ui_type == 18) { //文件
            _ui_mask = $.extend({
                storageType: 2,   //1-数据库存储，2-外部存储
                storageName: null, //外部存储库名
                accept: null,      //文件掩码 "image/*"
                chunk: false,       //分片上传
                blank: true,
                directup: false,      //文件选择后立即上传   
                onChange: function (target, value) {
                    //console.log($(this), target, value);
                }
            }, ui_mask);
        } else if (ui_type == 19) { //html
            _ui_mask = $.extend({
                type: 1,      //1-html，2-markdown
                storageType: 2,   //1-数据库存储，2-外部存储
                storageName: null, //外部存储库名
                accept: null,      //文件掩码 "image/*"
                chunk: false,       //分片上传
                blank: true,
                directup: false,      //文件选择后立即上传 
                onChange: function (target, value) {
                    //console.log($(this), target, value);
                }
            }, ui_mask);
        } else if (ui_type == 20) { //csv
            _ui_mask = $.extend({
                blank: true,
                ui_type: 2,
                ui_mask: {},
                separator: ",",
                default: "",
                isMove: true,
                editModeW: 500,
                editModeH: 300,
                onChange: function (target, value) {
                    //console.log($(this), target, value);
                }
            }, ui_mask);
        } else if (ui_type == 21) { //func
            _ui_mask = $.extend({
                blank: true,
                funcCallback: function (prevent_e, mdiinfo, callback) {
                    callback(true, "");
                },
                onChange: function (target, value) {
                    //console.log($(this), target, value);
                }
            }, ui_mask);
        } else if (ui_type == 900) { //ui_mask
            _ui_mask = $.extend({
                ui_type: 2,       //textbox
                pop_edit: false,    //弹出编辑模型
                blank: true,
                editModeW: 450,
                editModeH: 400,
            }, ui_mask);
        } else if (ui_type == 901) { //titles
            _ui_mask = $.extend({
                blank: true,
                type: 2,      //1-单数据 2-多数据
                onChange: function (target, value) {
                    //console.log($(this), target, value);
                }
            }, ui_mask);
        } else {
            _ui_mask = ui_mask;
        }

        return _ui_mask;
    },

    //保持data前格式化
    yqUiMaskSaveInit: function (ui_type, ui_mask) {
        var _ui_mask = $.extend({}, ui_mask);

        if (ui_type == 1) {   //textbox
            if (_ui_mask.default === null ||
                _ui_mask.default == "") {
                delete _ui_mask.default;
            }
        } else if (ui_type == 2) {   //textbox
            if (_ui_mask.default === null ||
                _ui_mask.default == "") {
                delete _ui_mask.default;
            }
            if (_ui_mask.min <= 0) {
                delete _ui_mask.min;
            }
            if (_ui_mask.max <= 0) {
                delete _ui_mask.max;
            }
            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }
            if (_ui_mask.format == "") {
                delete _ui_mask.format;
            }

            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }
        } else if (ui_type == 3) {  //checkbox
            if (_ui_mask.default == false) {
                delete _ui_mask.default;
            }
        } else if (ui_type == 4) {  //datebox
            var format = "yyyy/MM/dd";
            if (_ui_mask.format == "") {
                delete _ui_mask.format;
            }

            if (_ui_mask.default === null || _ui_mask.default == "") {
                delete _ui_mask.default;
            }
            else {
                _ui_mask.default = $.formatterdatebox(_ui_mask.default, format);
            }

            if (_ui_mask.min === null || _ui_mask.min == "") {
                delete _ui_mask.min;
            }
            else {
                _ui_mask.min = $.formatterdatebox(_ui_mask.min, format);
            }

            if (_ui_mask.max === null || _ui_mask.max == "") {
                delete _ui_mask.max;
            }
            else {
                _ui_mask.max = $.formatterdatebox(_ui_mask.max, format);
            }

            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }
        } else if (ui_type == 5) {   //richbox
            if (ui_mask.default === null || ui_mask.default === "") {
                _ui_mask.default = $.yqUiMask5_types[0].name;
            } else {
                for (var i = 0; i < $.yqUiMask5_types.length; i++) {
                    if ($.yqUiMask5_types[i].no == ui_mask.default) {
                        _ui_mask.default = $.yqUiMask5_types[i].name;
                        break;
                    }
                }
            }

            var types = [];
            if (ui_mask.types === undefined || ui_mask.types === null || ui_mask.types == "") {
                types.push($.yqUiMask5_types[0].name);
            }
            else {
                var _types = ui_mask.types.split(",");
                for (var i = 0; i < $.yqUiMask5_types.length; i++) {
                    for (var j = 0; j < _types.length; j++) {
                        if ($.yqUiMask5_types[i].no == parseInt(_types[j])) {
                            types.push($.yqUiMask5_types[i].name);
                            break;
                        }
                    }
                }
            }
            _ui_mask.types = types;

            if (_ui_mask.min <= 0) {
                delete _ui_mask.min;
            }
            if (_ui_mask.max <= 0) {
                delete _ui_mask.max;
            }
            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }
        } else if (ui_type == 6) {//Combobox
            if (!(_ui_mask.default === undefined) &&
                (_ui_mask.default === null ||
                    _ui_mask.default.length == 0)) {
                delete _ui_mask.default;
            }
            if (!(_ui_mask.lists === undefined) &&
                (_ui_mask.lists === null ||
                    _ui_mask.lists.length == 0)) {
                delete _ui_mask.lists;
            }

            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }

            if (typeof _ui_mask.type == "string") {
                if (_ui_mask.type != "string") {
                    delete _ui_mask.type;
                }
            } else {
                delete _ui_mask.type;
            }
        } else if (ui_type == 7) {//foreignkey
            if (_ui_mask.default === null || _ui_mask.default == "") {
                delete _ui_mask.default;
            }
            if (_ui_mask.dbName === null || _ui_mask.dbName == "") {
                delete _ui_mask.dbName;
            }
            if (_ui_mask.tbName === null || _ui_mask.tbName == "") {
                delete _ui_mask.tbName;
            }
            if (_ui_mask.tempNo <= -1) {
                delete _ui_mask.tempNo;
            }
            if (_ui_mask.displayType < -1) {
                delete _ui_mask.displayType;
            }
            if (_ui_mask.valueMember === null || _ui_mask.valueMember == "") {
                delete _ui_mask.valueMember;
            }
            if (_ui_mask.displayMember === null || _ui_mask.displayMember == "") {
                delete _ui_mask.displayMember;
            }
            if (!_ui_mask.isPage) {
                delete _ui_mask.pageSize;
            }
            if (_ui_mask.addWhere === null || _ui_mask.addWhere == "") {
                delete _ui_mask.addWhere;
            }
            if (_ui_mask.order === null || _ui_mask.order == "") {
                delete _ui_mask.order;
            }
            if (_ui_mask.expandMember === null || _ui_mask.expandMember == "") {
                delete _ui_mask.expandMember;
            }

            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }

            if (!(_ui_mask.mapping === undefined)) {
                if (_ui_mask.mapping.length == 0) {
                    delete _ui_mask.mapping;
                }
            }
        } else if (ui_type == 8) { //树形列表
            if (!(_ui_mask.default === undefined) &&
                (_ui_mask.default === null ||
                    _ui_mask.default.length == 0)) {
                delete _ui_mask.default;
            }
            if (_ui_mask.level === null) {
                _ui_mask.level = 1;
            }
            if (_ui_mask.subfield === null || _ui_mask.subfield == "") {
                delete _ui_mask.subfield;
            }
            if (!(_ui_mask.trees === undefined) && (
                _ui_mask.trees.length === null ||
                _ui_mask.trees.length == 0)) {
                delete _ui_mask.trees;
            }

            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }

            if (typeof _ui_mask.type == "string") {
                if (_ui_mask.type != "string") {
                    delete _ui_mask.type;
                }
            } else {
                delete _ui_mask.type;
            }
        } else if (ui_type == 9) {//NumberBox
            if (_ui_mask.default === null) {
                delete _ui_mask.default;
            }
            if (_ui_mask.min === null) {
                delete _ui_mask.min;
            }
            if (_ui_mask.max === null) {
                delete _ui_mask.max;
            }
            if (_ui_mask.groupSeparator === null || _ui_mask.groupSeparator === null) {
                delete _ui_mask.groupSeparator;
            }
            if (_ui_mask.precision <= 0) {
                delete _ui_mask.precision;
            }

            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }
        } else if (ui_type == 10) {//NumberSpinner
            if (_ui_mask.default === null) {
                delete _ui_mask.default;
            }
            if (_ui_mask.min === null) {
                delete _ui_mask.min;
            }
            if (_ui_mask.max === null) {
                delete _ui_mask.max;
            }
            if (_ui_mask.groupSeparator === null || _ui_mask.groupSeparator === null) {
                delete _ui_mask.groupSeparator;
            }

            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }
        } else if (ui_type == 11) { //TimeSpinner        
            if (_ui_mask.default === null) {
                delete _ui_mask.default;
            }
            if (_ui_mask.min === null) {
                delete _ui_mask.min;
            }
            if (_ui_mask.max === null) {
                delete _ui_mask.max;
            }
            if (!_ui_mask.seconds) {
                delete _ui_mask.seconds;
            }

            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }
        } else if (ui_type == 12) {//DateTimeBox
            if (_ui_mask.default === null) {
                delete _ui_mask.default;
            }
            if (_ui_mask.min === null) {
                delete _ui_mask.min;
            }
            if (_ui_mask.max === null) {
                delete _ui_mask.max;
            }
            if (!_ui_mask.seconds) {
                delete _ui_mask.seconds;
            }

            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }
        } else if (ui_type == 13) {//NCheckBox
            if (_ui_mask.lists === null) {
                delete _ui_mask.lists;
            } else {
                var default_ = "";
                for (let i = 0; i < _ui_mask.lists.length; i++) {
                    if (!(_ui_mask.lists[i].checked === undefined)) {
                        if (_ui_mask.lists[i].checked) {
                            default_ += (default_ == "" ? "" : ",") + _ui_mask.lists[i].no;
                        }
                    }
                }
                if (default_ != "") {
                    _ui_mask.default = default_;
                } else {
                    delete _ui_mask.default;
                }
            }

            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }

            if (typeof _ui_mask.type == "string") {
                if (_ui_mask.type != "string") {
                    delete _ui_mask.type;
                }
            } else {
                delete _ui_mask.type;
            }
        } else if (ui_type == 14) {//NForeignKey
            if (_ui_mask.default === null || _ui_mask.default == "") {
                delete _ui_mask.default;
            }
            if (_ui_mask.dbName === null || _ui_mask.dbName == "") {
                delete _ui_mask.dbName;
            }
            if (_ui_mask.tbName === null || _ui_mask.tbName == "") {
                delete _ui_mask.tbName;
            }
            if (_ui_mask.tempNo <= -1) {
                delete _ui_mask.tempNo;
            }
            if (_ui_mask.displayType < -1) {
                delete _ui_mask.displayType;
            }
            if (_ui_mask.valueMember === null || _ui_mask.valueMember == "") {
                delete _ui_mask.valueMember;
            }
            if (_ui_mask.displayMember === null || _ui_mask.displayMember == "") {
                delete _ui_mask.displayMember;
            }
            if (!_ui_mask.isPage) {
                delete _ui_mask.pageSize;
            }
            if (_ui_mask.addWhere === null || _ui_mask.addWhere == "") {
                delete _ui_mask.addWhere;
            }
            if (_ui_mask.order === null || _ui_mask.order == "") {
                delete _ui_mask.order;
            }
            if (_ui_mask.expandMember === null || _ui_mask.expandMember == "") {
                delete _ui_mask.expandMember;
            }

            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }

            if (!(_ui_mask.mapping === undefined)) {
                if (_ui_mask.mapping.length == 0) {
                    delete _ui_mask.mapping;
                }
            }
        } else if (ui_type == 15) {//TbEdit 表格数据
            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }
            if (_ui_mask.ajaxUrl === undefined || _ui_mask.ajaxUrl === null ||
                _ui_mask.ajaxUrl == ""
            ) {
                delete _ui_mask.ajaxUrl;
            }
            if (_ui_mask.editModeW === undefined || _ui_mask.editModeW === null) {
                delete _ui_mask.editModeW;
            }
            if (_ui_mask.editModeH === undefined || _ui_mask.editModeH === null) {
                delete _ui_mask.editModeH;
            }
            if (!(_ui_mask.editType == 1 || _ui_mask.editType == 2)) {
                _ui_mask.editType = 0;
            }
            if (_ui_mask.modelNo === undefined || _ui_mask.modelNo === null) {
                delete _ui_mask.modelNo;
            }
            if (_ui_mask.panelWidth === undefined || _ui_mask.panelWidth === null) {
                delete _ui_mask.panelWidth;
            }
            if (_ui_mask.panelHeight === undefined || _ui_mask.panelHeight === null) {
                delete _ui_mask.panelHeight;
            }

            if (typeof _ui_mask.param != "object") {
                delete _ui_mask.param;
            } else {
                if (_ui_mask.param.titles === undefined || _ui_mask.param.titles === null) {
                    _ui_mask.param.titles = [];
                }
                if (_ui_mask.param.model === undefined || _ui_mask.param.model === null) {
                    _ui_mask.param.model = [];
                }
            }
        } else if (ui_type == 16) { //tree 属性数据
            if (_ui_mask.displayMember === undefined || _ui_mask.displayMember === null) {
                delete _ui_mask.displayMember;
            }
            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }
            if (_ui_mask.ajaxUrl === undefined || _ui_mask.ajaxUrl === null ||
                _ui_mask.ajaxUrl == ""
            ) {
                delete _ui_mask.ajaxUrl;
            }
            if (_ui_mask.editModeW === undefined || _ui_mask.editModeW === null) {
                delete _ui_mask.editModeW;
            }
            if (_ui_mask.editModeH === undefined || _ui_mask.editModeH === null) {
                delete _ui_mask.editModeH;
            }
            if (!(_ui_mask.editType == 1 || _ui_mask.editType == 2)) {
                _ui_mask.editType = 0;
            }
            if (_ui_mask.modelNo === undefined || _ui_mask.modelNo === null) {
                delete _ui_mask.modelNo;
            }
            if (_ui_mask.panelWidth === undefined || _ui_mask.panelWidth === null) {
                delete _ui_mask.panelWidth;
            }
            if (_ui_mask.panelHeight === undefined || _ui_mask.panelHeight === null) {
                delete _ui_mask.panelHeight;
            }

            if (typeof _ui_mask.param != "object") {
                delete _ui_mask.param;
            } else {
                if (_ui_mask.param.titles === undefined || _ui_mask.param.titles === null) {
                    _ui_mask.param.titles = [];
                }
                if (_ui_mask.param.model === undefined || _ui_mask.param.model === null) {
                    _ui_mask.param.model = [];
                }
            }
        } else if (ui_type == 17) { //attr 属性数据
            if (_ui_mask.blank === null || _ui_mask.blank) {
                delete _ui_mask.blank;
            }
            if (_ui_mask.ajaxUrl === undefined || _ui_mask.ajaxUrl === null ||
                _ui_mask.ajaxUrl == ""
            ) {
                delete _ui_mask.ajaxUrl;
            }
            if (!(_ui_mask.editType === 1 || _ui_mask.editType == 2)) {
                delete _ui_mask.editType;
            }
            if (_ui_mask.modelNo === null || _ui_mask.modelNo == -1) {
                delete _ui_mask.modelNo;
            }
            if (typeof _ui_mask.param != "object") {
                delete _ui_mask.param;
            } else {
                if (_ui_mask.param.titles === undefined || _ui_mask.param.titles === null) {
                    _ui_mask.param.titles = [];
                }
                if (_ui_mask.param.model === undefined || _ui_mask.param.model === null) {
                    _ui_mask.param.model = [];
                }
            }
            if (_ui_mask.loadDefault === null || _ui_mask.loadDefault == false) {
                delete _ui_mask.loadDefault;
            }

            if (_ui_mask.editModeW === undefined || _ui_mask.editModeW === null) {
                delete _ui_mask.editModeW;
            }
            if (_ui_mask.editModeH === undefined || _ui_mask.editModeH === null) {
                delete _ui_mask.editModeH;
            }
        } else if (ui_type == 18) {//文件数据

            if (_ui_mask.storageType === null) {
                _ui_mask.storageType = 2;
            }
            if (_ui_mask.storageName === null) {
                delete _ui_mask.storageName;
            }
            if (_ui_mask.accept === null) {
                delete _ui_mask.accept;
            }
            if (_ui_mask.chunk == false) {
                delete _ui_mask.chunk;
            }
            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }
            if (_ui_mask.directup == false) {
                delete _ui_mask.directup;
            }
        } else if (ui_type == 19) { //html
            if (_ui_mask.type === null) {
                _ui_mask.type = 1;
            }
            if (_ui_mask.storageType === null) {
                _ui_mask.storageType = 2;
            }
            if (_ui_mask.storageName === null) {
                delete _ui_mask.storageName;
            }
            if (_ui_mask.accept === null) {
                delete _ui_mask.accept;
            }
            if (_ui_mask.chunk == false) {
                delete _ui_mask.chunk;
            }
            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }
            if (_ui_mask.directup == false) {
                delete _ui_mask.directup;
            }
        } else if (ui_type == 20) {//csv
            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }
            if (_ui_mask.ui_type === undefined || _ui_mask.ui_type === null) {
                delete _ui_mask.ui_type;
            }
            if (_ui_mask.separator === undefined || _ui_mask.separator === null ||
                _ui_mask.separator === ""
            ) {
                delete _ui_mask.separator;
            }
            if (_ui_mask.default === undefined || _ui_mask.default === null) {
                delete _ui_mask.default;
            }
            if (_ui_mask.editModeW === undefined || _ui_mask.editModeW === null) {
                delete _ui_mask.editModeW;
            }
            if (_ui_mask.editModeH === undefined || _ui_mask.editModeH === null) {
                delete _ui_mask.editModeH;
            }
        } else if (ui_type == 21) {//func
            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }
        } else if (ui_type == 900) { //ui_mask
            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }
            if (_ui_mask.pop_edit == false) {
                delete _ui_mask.pop_edit;
            }
            if (_ui_mask.ui_type === null) {
                _ui_mask.ui_type = 1;
                //delete _ui_mask.ui_type;
            }

            if (_ui_mask.editModeW === undefined || _ui_mask.editModeW === null) {
                delete _ui_mask.editModeW;
            }
            if (_ui_mask.editModeH === undefined || _ui_mask.editModeH === null) {
                delete _ui_mask.editModeH;
            }
        } else if (ui_type == 901) { //titles
            if (_ui_mask.blank == true) {
                delete _ui_mask.blank;
            }
            if (_ui_mask.type === null ||
                !(_ui_mask.type == 1 || _ui_mask.type == 2)) {
                _ui_mask.type = 2;
            }
        }

        return _ui_mask;
    },

    //RichTextBox 格式类型
    yqUiMask5_types: [
        { no: 0, name: "base" },
        { no: 1, name: "html" },
        { no: 2, name: "aspx" },
        { no: 3, name: "js" },
        { no: 4, name: "css" },
        { no: 5, name: "txt" },
        { no: 6, name: "json" },
        { no: 7, name: "sql" }
    ],

    //表格列表父子数据转为树形数据格
    yqListToTree: function (opts, callback) {
        var options = {
            idName: "sid",             //id字段名称
            pidName: "pid",            //pid字段名称
            rows: []                    //数据         
        };

        var o = $.extend({}, options, opts);

        if (o.pidVal == "") {
            o.pidVal = null;
        }
        if (o.idName === null) {
            o.idName = "sid";
        }
        if (o.pidName === null) {
            o.pidName = "pid";
        }
        if (o.childrenName === null) {
            o.childrenName = "children";
        }

        callback(getJsonTree(o.pidVal));

        function getJsonTree(parentVal) {
            var nodes = [];
            for (var i = 0; i < o.rows.length; i++) {
                //data.splice(i, 1)
                if ((parentVal === null && (o.rows[i][o.pidName] === undefined || o.rows[i][o.pidName] === null))
                    || (parentVal != null && o.rows[i][o.pidName] == parentVal)
                ) {
                    var row = $.extend({}, o.rows[i]);
                    var result = getJsonTree(row[o.idName]);
                    if (result.length > 0) {
                        row["subs"] = result;
                    }
                    nodes.push(row);
                }
            }

            return nodes;
        }
    },

    //树形数据格转为表格列表父子数据
    yqTreeTolist: function (opts, callback) {
        var options = {
            idName: "sid",             //id字段名称
            pidName: "pid",            //pid字段名称
            rows: []                    //数据         
        };

        var o = $.extend({}, options, opts);

        if (o.pidVal == "") {
            o.pidVal = null;
        }
        if (o.idName === null) {
            o.idName = "sid";
        }
        if (o.pidName === null) {
            o.pidName = "pid";
        }
        if (o.childrenName === null) {
            o.childrenName = "children";
        }

        callback(getJsonTree(o.rows, o.pidVal));

        function getJsonTree(f_rows, pval) {
            var t_rows = [];
            for (var i = 0; i < f_rows.length; i++) {
                var subs = [];
                var row = JSON.parse(JSON.stringify(f_rows[i]));
                if (!(f_rows[i].subs === undefined)) {
                    subs = row.subs;
                }
                delete row.subs;
                row[o.pidName] = pval;
                t_rows.push(row);

                if (subs.length > 0) {
                    var _rows = getJsonTree(subs, row[o.idName]);
                    for (var j = 0; j < _rows.length; j++) {
                        t_rows.push(_rows[j]);
                    }
                }
            }

            return t_rows;
        }
    },

    /*加载到结构树前处理
    返回： {
               id_: 99,
               data: []
           }
    */
    yqTreeloadInit: function (data, txtname) {
        /*
        var data = [
           {
                no: 1,
                name: "name1",
                subs: [{
                    no: 101,
                    name: "name101",
                    subs: [{},...]
                }, ...]
            },
            ...
        ];
        */

        if (txtname === undefined || txtname == "") {
            txtname = null;
        }
        //console.log("data", data);

        return formatData(data, 0);

        function formatData(data, id_) {
            var nodes_ = [];
            for (let i = 0; i < data.length; i++) {
                var node_ = $.extend({}, data[i]);
                id_++;
                node_["id_"] = id_;
                if (!(txtname === null)) {
                    node_.text = node_[txtname];
                }
                if (typeof node_.subs != "undefined") {
                    if (node_.subs.length > 0) {
                        var res_ = formatData(node_.subs, id_);
                        node_.children = res_.data;
                        node_.state = "closed";
                        id_ = res_.id_;
                        delete node_.subs;
                    }
                }

                nodes_.push(node_);
            }

            return {
                id_: id_,
                data: nodes_
            };
        }
    },
    /*从结构树保存处理
      返回：[]
     */
    yqTreeSaveInit: function (data) {
        /*
        var data = [
           {
                id_: 1,
                no: 1,
                name: "name1",
                children: [{
                    id_ : 2,
                    no: 101,
                    name: "name101",
                    children: [{},...]
                }, ...]
            },
            ...
        ];
        */

        return formatData(data);

        function formatData(data) {
            var nodes_ = [];
            for (let i = 0; i < data.length; i++) {
                var node_ = $.extend({}, data[i]);
                if (typeof node_.children != "undefined") {
                    if (node_.children.length > 0) {
                        node_.subs = formatData(node_.children);
                    }
                }
                delete node_.id_;
                delete node_.checkState;
                delete node_.checked;
                delete node_.state;
                delete node_._parentId;
                delete node_.children;
                delete node_.multi;

                //莫名其妙的原因添加的
                delete node_.undefined;

                nodes_.push(node_);
            }

            return nodes_;
        }
    }
});

//数据相关
jQuery.extend({
    //树形数据格式化
    yqToTrees: function (opts, callback) {
        var options = {
            pidVal: null,              //根节点父项属性值
            idName: "sid",             //id字段名称
            pidName: "pid",            //pid字段名称
            displayMember: "name",      //显示字段
            rows: []                    //数据         
        };

        var o = $.extend({}, options, opts);

        if (o.pidVal == "") {
            o.pidVal = null;
        }
        if (o.idName === null) {
            o.idName = "sid";
        }
        if (o.pidName === null) {
            o.pidName = "pid";
        }
        if (o.childrenName === null) {
            o.childrenName = "children";
        }

        callback(getJsonTree(o.pidVal));

        function getJsonTree(parentVal) {
            var nodes = [];
            for (var i = 0; i < o.rows.length; i++) {
                //data.splice(i, 1)
                if ((parentVal === null && (o.rows[i][o.pidName] === undefined || o.rows[i][o.pidName] === null))
                    || (parentVal != null && o.rows[i][o.pidName] == parentVal)
                ) {
                    var row = $.extend({}, o.rows[i]);

                    var node = {
                        "id": row[o.idName],
                        "text": $.getDisplayValue(row, o.displayMember),
                        attributes: row
                    };

                    if (typeof row.iconCls == "string") {
                        node.iconCls = row.iconCls;
                    }

                    var result = getJsonTree(row[o.idName]);
                    if (result.length > 0) {
                        node["children"] = result;
                        node["state"] = "closed";
                    }
                    nodes.push(node);
                }
            }

            return nodes;
        }
    },
    //数据行格式化 显示时
    yqFmToViews: function (rows, titles) {
        var _rows = [];
        for (var i = 0; i < rows.length; i++) {
            _rows.push($.yqFmToView(rows[i], titles));
        }
        return _rows;
    },
    //数据行格式化 显示时
    yqFmToView: function (row, titles) {
        var _row = {};
        for (var i = 0; i < titles.length; i++) {
            var title = titles[i];
            if (!title.is_func) {
                var val = row[title.name];

                if (val === undefined) {
                    val = null;
                }

                if (title.ui_type == 1 || title.ui_type == 2) {   //1-label,2-textbox
                    val = $.yqToString(val);
                }
                else if (title.ui_type == 3) {   //checkbox
                    val = $.yqToBoolean(val);
                }
                else if (title.ui_type == 4) {   //datebox  字符过度
                    if (!(val === null)) {
                        val = $.convert_todate(val);
                    }
                }
                else if (title.ui_type == 5) {   //5-richbox
                    val = $.yqToString(val);
                }
                else if (title.ui_type == 6) {   //combobox
                    if (title.ui_mask.type == "string") {
                        val = $.yqToString(val);
                    } else {
                        val = $.yqToInt(val);
                    }
                }
                else if (title.ui_type == 7) {   //7-foreignkey
                    val = $.yqToString(val);
                }
                else if (title.ui_type == 8) {   //treeselect
                    if (title.ui_mask.type == "string") {
                        val = $.yqToString(val);
                    } else {
                        val = $.yqToInt(val);
                    }
                }
                if (title.ui_type == 9) {   //numberbox
                    val = $.yqToNumber(val);
                }
                else if (title.ui_type == 10) {   //numberspinner
                    val = $.yqToInt(val);
                }
                else if (title.ui_type == 11) {   //timespinner
                    //val = $.formattertimespinner(val, title.ui_mask.format);
                }
                else if (title.ui_type == 12) {   //datetimebox   字符过度
                    val = $.convert_todate(val);
                }
                else if (title.ui_type == 13) {   //ncheckbox 
                    val = $.yqToString(val);
                }
                else if (title.ui_type == 14) {   //nforeignkey 
                    val = $.yqToString(val);
                }
                else if (title.ui_type == 15) {   //tbedit 
                    if (typeof val == "string") {
                        try {
                            val = JSON.parse(val);
                        } catch {
                            val = null;
                        }
                    }
                    else if (typeof val != "object") {
                        val = null;
                    }
                }
                else if (title.ui_type == 16) {   //tree 
                    if (typeof val == "string") {
                        if (typeof val == "string") {
                            try {
                                val = JSON.parse(val);
                            } catch {
                                val = null;
                            }
                        }
                    }
                    else if (typeof val != "object") {
                        val = null;
                    }
                }
                else if (title.ui_type == 17) {   //attr 
                    if (typeof val == "string") {
                        if (typeof val == "string") {
                            try {
                                val = JSON.parse(val);
                            } catch {
                                val = null;
                            }
                        }
                    }
                    else if (typeof val != "object") {
                        val = null;
                    }
                }

                else if (title.ui_type == 18) {   //filebox   文件
                    if (typeof val == "string") {
                        if (typeof val == "string") {
                            try {
                                val = JSON.parse(val);
                            } catch {
                                val = null;
                            }
                        }
                    }
                    else if (typeof val != "object") {
                        val = null;
                    }
                }
                else if (title.ui_type == 19) {   //html
                    if (typeof val == "string") {
                        if (typeof val == "string") {
                            try {
                                val = JSON.parse(val);
                            } catch {
                                val = null;
                            }
                        }
                    }
                    else if (typeof val != "object") {
                        val = null;
                    }
                }

                else if (title.ui_type == 901) {   //titles定义
                    if (typeof val == "string") {
                        if (typeof val == "string") {
                            try {
                                val = JSON.parse(val);
                            } catch {
                                val = null;
                            }
                        }
                    }
                    else if (typeof val != "object") {
                        val = null;
                    }
                }

                _row[title.name] = val;
            }
        }

        return _row;
    },
    //数据行格式化 保持到数据库时
    yqFmToDatas: function (rows, titles, fk_rows) {
        if (fk_rows === undefined) {
            fk_rows = [];
        }

        var _rows = [];
        for (let i = 0; i < rows.length; i++) {
            _rows.push($.yqFmToData(rows[i], titles, fk_rows, false));
        }
        return _rows;
    },
    //数据行格式化 保持到数据库时   istb：数据库字段
    yqFmToData: function (row, titles, fk_rows, istb) {
        if (fk_rows === undefined) {
            fk_rows = [];
        }
        if (istb === undefined) {
            istb = true;
        }
        var _row = {};
        for (var i = 0; i < titles.length; i++) {
            var title = titles[i];

            if (!title.is_func) {
                var val = $.yqFmToVal(row[title.name], title, istb);

                if (typeof val != "undefined") {
                    if (!(val === null) && val.toString() != "") {
                        _row[title.name] = val;
                    }
                }

            }
        }

        if (!(row["subs"] === undefined || row["subs"] === null)) {
            _row["subs"] = $.yqFmToDatas(row["subs"], titles, fk_rows);
        }

        return _row;
    },

    //字段数数据格式化 保持到数据库时   istb：数据库字段
    yqFmToVal: function (val, title, istb) {
        if (istb === undefined) {
            istb = true;
        }

        if (typeof val != "undefined") {
            if (title.ui_type == 1 || title.ui_type == 2) {   //1-label,2-textbox
                val = $.yqToString(val);
            }
            else if (title.ui_type == 3) {   //3-checkbox
                val = $.yqToBoolean(val);
            }
            else if (title.ui_type == 4) {   //datebox
                val = $.formatDateToRFC3339(val);
            }
            if (title.ui_type == 5) {   //5-richbox
                val = $.yqToString(val);
            }
            else if (title.ui_type == 6) {   //6-combobox
                if (title.ui_mask.type == "string") {
                    val = $.yqToString(val);
                } else {
                    val = $.yqToInt(val);
                }
            }
            if (title.ui_type == 7) {   //7-foreignkey
                val = $.yqToString(val);
            }
            else if (title.ui_type == 8) {   //8-treeselect
                if (title.ui_mask.type == "string") {
                    val = $.yqToString(val);
                } else {
                    val = $.yqToInt(val);
                }
            }
            else if (title.ui_type == 9) {   //numberbox  
                val = $.yqToNumber(val);
            }
            else if (title.ui_type == 10) {   //numberspinner
                val = $.yqToInt(val);
            }
            else if (title.ui_type == 11) {   //timespinner
                console.log("timespinner",val)
                //val = $.formatDateToRFC3339(val);
            }
            else if (title.ui_type == 12) {   //datetimebox
                val = $.formatDateToRFC3339(val);
            }

            else if (title.ui_type == 13) {   //ncheckbox 
                val = $.yqToString(val);
            }
            else if (title.ui_type == 14) {   //nforeignkey 
                val = $.yqToString(val);
            }
            else if (title.ui_type == 15 ||//tbedit 
                title.ui_type == 16 ||     //tree 
                title.ui_type == 17) {     //attr  
                if (istb) {
                    if (!(val === null)) {
                        if (typeof val == "object") {
                            val = JSON.stringify(val);
                        }
                    }
                } else {
                    if (typeof val == "string") {
                        try {
                            val = JSON.parse(val);
                        } catch {
                            val = null;
                        }
                    }
                }
            }
            else if (title.ui_type == 18) {   //filebox   文件
                if (typeof val == "string") {
                    try {
                        val = JSON.parse(val);
                    } catch {
                        val = null;
                    }
                }
                else if (typeof val != "object") {
                    val = null;
                }
            }
            else if (title.ui_type == 19) {   //html
                if (typeof val == "string") {
                    if (typeof val == "string") {
                        try {
                            val = JSON.parse(val);
                        } catch {
                            val = null;
                        }
                    }
                }
                else if (typeof val != "object") {
                    val = null;
                }
            }
            else if (title.ui_type == 20) {   //csv
                if (istb) {
                    if (!(val === null)) {
                        if (typeof val == "object") {
                            val = JSON.stringify(val);
                        }
                    }
                } else {
                    if (typeof val == "string" && val.length > 0) {
                        var separator = title.ui_mask.separator === undefined ? "," : title.ui_mask.separator;
                        val = val.split(separator);
                        console.log("title.ui_type", title, val);
                    }
                }
            }
            else if (title.ui_type == 21) {   //Func

            }
            else if (title.ui_type == 901) {   //titles定义
                if (istb) {
                    if (!(val === null)) {
                        if (typeof val == "object") {
                            val = JSON.stringify(val);
                        }
                    }
                } else {
                    if (typeof val == "string") {
                        try {
                            val = JSON.parse(val);
                        } catch {
                            val = null;
                        }
                    }
                }
            }
        }

        return val;
    },


    //取得数据默认值
    yqGetDefaultRow: function (titles) {
        var defaultRow = {};
        for (var i = 0; i < titles.length; i++) {
            var title = titles[i];
            if (!title.is_func && title.ui_visible) {
                if (title.ui_type == 1) {
                    if (!(title.ui_mask.default === null)) {
                        defaultRow[title.name] = title.ui_mask.default;
                    }
                }
                else if (title.ui_type == 2) { //textbox
                    if (!(title.ui_mask.default === null)) {
                        defaultRow[title.name] = title.ui_mask.default;
                    }
                }
                else if (title.ui_type == 3) { //checkbox
                    if (!(title.ui_mask.default === null)) {
                        defaultRow[title.name] = title.ui_mask.default;
                    }
                }
                else if (title.ui_type == 4) { //datebox
                    if (!(title.ui_mask.default === null)) {
                        defaultRow[title.name] = title.ui_mask.default;
                    }
                }
                else if (title.ui_type == 5) { //richbox
                    if (!(title.ui_mask.default === null)) {
                        defaultRow[title.name] = title.ui_mask.default;
                    }
                }
                else if (title.ui_type == 6) { //Combobox
                    if (!(title.ui_mask.default === null || title.ui_mask.default == -1)) {
                        defaultRow[title.name] = title.ui_mask.default;
                    }
                }
                else if (title.ui_type == 7) { //foreignkey
                    if (!(title.ui_mask.default === null)) {
                        defaultRow[title.name] = title.ui_mask.default;
                    }
                }
                else if (title.ui_type == 8) { //树形列表                   
                    if (title.ui_mask.level == 1 && !(title.ui_mask.default === null)) {
                        defaultRow[title.name] = title.ui_mask.default[0];
                        var level = 1;
                        var subfield = title.ui_mask.subfield;
                        while (!(subfield === null || subfield == "") &&
                            title.ui_mask.default.length >= level
                        ) {
                            for (var j = 0; j < titles.length; j++) {
                                if (titles[j].name == subfield) {
                                    defaultRow[subfield] = title.ui_mask.default[level];
                                    level++;
                                    subfield = titles[j].ui_mask.subfield;
                                    if (subfield === undefined) {
                                        subfield = "";
                                    }
                                }
                            }
                        }
                    }
                }
                else if (title.ui_type == 9) { //NumberBox
                    if (!(title.ui_mask.default === null)) {
                        defaultRow[title.name] = title.ui_mask.default;
                    }
                }
                else if (title.ui_type == 10) { //NumberSpinner
                    if (!(title.ui_mask.default === null)) {
                        defaultRow[title.name] = title.ui_mask.default;
                    }
                }
                else if (title.ui_type == 11) { //TimeSpinner
                    if (!(title.ui_mask.default === null)) {
                        defaultRow[title.name] = title.ui_mask.default;
                    }
                }
                else if (title.ui_type == 12) { //DateTimeBox
                    if (!(title.ui_mask.default === null)) {
                        defaultRow[title.name] = title.ui_mask.default;
                    }
                }
                else if (title.ui_type == 13) { //NCheckBox 多选 

                }
                else if (title.ui_type == 14) { //NForeignKey 多选外键

                }
                else if (title.ui_type == 15) { //TbEdit 表格数据

                }
                else if (title.ui_type == 16) {  //tree 数据

                }
                else if (title.ui_type == 17) {  //attr 属性数据

                }
                else if (title.ui_type == 18) {  //VirtualUi 虚表模板数据

                }
            }
        }

        return defaultRow;
    },
    //外键数据获取数据处理参数
    yqFmForienKeys: function (rows, titles) {
        var fks = [];
        for (var i = 0; i < titles.length; i++) {
            if ((titles[i].ui_type == 7 || titles[i].ui_type == 14) &&
                titles[i].ui_visible)  //外键
            {
                var fk = {
                    dbname: titles[i].ui_mask.dbName,      //数据库
                    tbname: titles[i].ui_mask.tbName,      //表
                    field: titles[i].name,                 //关键字段
                    keyid: titles[i].ui_mask.valueMember,   //关键字段}
                    ids: []
                }

                for (let j = 0; j < rows.length; j++) {
                    val = rows[j][titles[i].name];
                    if (typeof val != "undefined" &&
                        !(val === null) && val.toString() != "") {
                        if (typeof val != 'string') {
                            val = val.toString();
                        }
                        var s_ = val.split(",");
                        for (let s_i = 0; s_i < s_.length; s_i++) {
                            const eitem = s_[s_i];
                            var hasitem = false;
                            for (let l = 0; l < fk.ids.length; l++) {
                                if (eitem == fk.ids[l]) {
                                    hasitem = true;
                                    break;
                                }
                            }

                            if (!hasitem) {
                                fk.ids.push(eitem);
                            }
                        }
                    }
                }

                if (fk.ids.length > 0) {
                    fks.push(fk);
                }
            }
        }
        return fks;
    },
    //取得外键
    yqGetForeignkeys: function (opts, callback) {
        var o = $.extend({
            "ajaxUrl": "/_db.html",
            "rows": [],
            "titles": [],
            "fk_rows": []
        }, opts);

        fk_rows = o.fk_rows;
        //外键处理
        var fks = $.yqFmForienKeys(o.rows, o.titles);
        var fks2 = [];
        for (let j = 0; j < fks.length; j++) {
            var hasitem = false;
            for (let i = 0; i < fk_rows.length; i++) {
                if (fks[j].field == fk_rows[i].field) {
                    var ids = [];
                    for (let j2 = 0; j2 < fks[j].ids.length; j2++) {

                        var hasitem2 = false;
                        for (let i2 = 0; i2 < fk_rows[i].rows.length; i2++) {
                            if (fks[j].ids[j2] == fk_rows[i].rows[i2][fks[j].keyid]) {
                                hasitem2 = true;
                                break;
                            }
                        }

                        if (!hasitem2) {
                            ids.push(fks[j].ids[j2])
                        }
                    }

                    fks[j].ids = ids;
                    break;
                }
            }

            if (fks[j].ids.length > 0) {
                fks2.push(fks[j]);
            }
        }

        fks = fks2;

        if (fks.length > 0) {
            $.yqDbTbForienKey({
                ajaxUrl: o.ajaxUrl,
                rows: fks
            },
                function (res) {
                    //console.log("fksdata", res);
                    if (res.error == 0) {
                        for (let j = 0; j < res.rows.length; j++) {
                            var hasitem = false;
                            for (let i = 0; i < fk_rows.length; i++) {
                                if (fk_rows[i].field == res.rows[j].field) {
                                    for (let l = 0; l < res.rows[j].rows.length; l++) {
                                        fk_rows[i].rows.push(res.rows[j].rows[l]);
                                    }

                                    hasitem = true;
                                    break;
                                }
                            }

                            if (!hasitem) {
                                fk_rows.push(res.rows[j]);
                            }
                        }
                    }

                    callback(fk_rows);
                });
        }
        else {
            callback(fk_rows);
        }
    }
});

//弹窗编辑器插件
jQuery.extend({
    pop_yqEditor: {
        //HtmlEdit uitype=19
        yqTextRichBox: function (prevent_e, options) {
            var $object = this;
            var opt = prevent_e.options;
            options = $.extend({
                value: null,
                blank: true,
                min: null,
                max: null,
                types: ["base"],
                type: "base",
                isEdit: true,   //可编辑
                editModeW: 400, //模态编辑器宽度 格式为 800（数字）
                editModeH: 300, //模态编辑器高度 格式为 600（数字）
            }, options);
            var mdiinfo = $.yqGetWindParams();

            var run_opt = {
                mdiinfo: mdiinfo,
                prevent_e: prevent_e,
                width: options.editModeW,
                height: options.editModeH,

                types: options.types,
                type: options.type,
                min: options.min,
                max: options.max,
                value: options.value,
                isEdit: options.isEdit,

                callback: function (val) {
                    var yqtype;
                    if (opt.p_target === undefined) {
                        yqtype = $object.data("yqtype");
                    } else {
                        var ed = $.yqTextEditor(opt.p_target, opt.p_field);
                        yqtype = $(ed.target).data("yqtype");
                    }

                    $.pop_yqEditorAfter[yqtype]($object, opt, (val === null ? "" : val.value));
                }
            };

            if (window.top == window.self) {
                $.yqCodePopEdit(run_opt);
            }
            else {
                window.top.$.yqCodePopEdit(run_opt);
            }
        },

        //csv编辑器 ui_type:20
        yqTextCSV: function (prevent_e, options) {
            var $object = this;
            var opt = prevent_e.options;
            options = $.extend({
                ui_type: 2,  //输入值类型 2:文本 4:日期 9:numberBox 10:numberSpinner,11timeSpinner,12:dateTimeSpinner
                ui_mask: {}, //掩码
                separator: ",", //分隔符
                value: "", //默认值
                isEdit: true,
                isAdd: true,
                isDel: true,
                isMove: true,
                editModeW: 500, //模态编辑器宽度 格式为 800（数字）
                editModeH: 300, //模态编辑器高度 格式为 600（数字）
            }, options);
            var mdiinfo = $.yqGetWindParams();

            var rows = [];
            if (Object.prototype.toString.call(options.value) === '[object Array]') {
                rows = options.value;
            } else if (typeof options.value == "string" && options.value != "") {
                var arr = options.value.split(options.separator);
                for (var i = 0; i < arr.length; i++) {
                    rows.push({ "name": arr[i] });
                }
            }

            var titles = [{
                "is_func": false,
                "name": "name",
                "ui_title": options.ui_title,
                "ui_type": 2,
                "ui_width": options.editModeW - 58,
                "ui_visible": true,
                "ui_readonly": false,
                "ui_mask": options.ui_mask
            }];

            var run_opt = {
                mdiinfo: mdiinfo,
                prevent_e: prevent_e,
                width: options.editModeW,
                height: options.editModeH,
                titles: titles,
                rows: rows,
                isEdit: options.isEdit,
                isAdd: options.isAdd,
                isDel: options.isDel,
                isMove: options.isMove,
                toexcel: false,
                inexcel: false,
                frozenNum: 0, //锁定列数量（锁定左侧）
                rownumbers: true,
                showHeader: false, //显示表头
                sumList: [],
                callback: function (rows) {
                    var separator = options.separator === undefined ? "," : options.separator;

                    var value_ = "";
                    if (rows.length > 0) {
                        for (var i = 0; i < rows.length; i++) {
                            if (!(rows[i]["name"] === undefined ||
                                rows[i]["name"] === null ||
                                rows[i]["name"] === ""))
                                value_ += (value_ == "" ? "" : separator) + rows[i]["name"];
                        }
                    }

                    var yqtype;
                    if (opt.p_target === undefined) {
                        yqtype = $object.data("yqtype");
                    } else {
                        var ed = $.yqTextEditor(opt.p_target, opt.p_field);
                        yqtype = $(ed.target).data("yqtype");
                    }

                    $.pop_yqEditorAfter[yqtype]($object, opt, value_);
                }
            };

            if (typeof options.beforeBindingTitle == "function") {
                run_opt.beforeBindingTitle = options.beforeBindingTitle;
            }
            if (typeof options.afterBindingTitle == "function") {
                run_opt.afterBindingTitle = options.afterBindingTitle;
            }
            if (typeof options.onClickRow == "function") {
                run_opt.onClickRow = options.onClickRow;
            }
            if (typeof options.endEditing == "function") {
                run_opt.endEditing = options.endEditing;
            }
            if (typeof options.beforeAdd == "function") {
                run_opt.beforeAdd = options.beforeAdd;
            }

            if (window.top == window.self) {
                $.yqTableEditPopEdit(run_opt);
            }
            else {
                window.top.$.yqTableEditPopEdit(run_opt);
            }
        },
    },
    pop_yqEditorAfter: {
        //HtmlEdit uitype=19
        yqTextRichBox: function ($object, opt, value) {
            //嵌入到datagrid中，兼容处理（需要重新创建对象）
            if (typeof opt.p_target != "undefined") {
                var ed = $.yqTextEditor(opt.p_target, opt.p_field);
                if (!(ed === null)) {
                    if (opt.value != value) {
                        $.yqDgEditorSetValue(ed.target, value);
                        opt.afterChange.call($(ed.target), value);
                    }
                }
            }
            else {
                if (opt.value != value) {
                    $object.yqTextRichBox('setValue', value);
                    opt.afterChange.call($object, value);
                }
            }
        },
        //csv编辑器 ui_type:20
        yqTextCSV: function ($object, opt, value) {
            //嵌入到datagrid中，兼容处理（需要重新创建对象）
            if (typeof opt.p_target != "undefined") {
                var ed = $.yqTextEditor(opt.p_target, opt.p_field);
                if (!(ed === null)) {
                    $.yqDgEditorSetValue(ed.target, value);
                    //$(ed.target).yqTextCSV('setValue', value);
                    opt.afterChange.call($(ed.target), value);
                }
            }
            else {
                $object.yqTextCSV("setValue", value);
                opt.afterChange.call($object, value);
            }
        },
    }
});

//datagrid编辑器扩展
jQuery.extend({
    //取得text编辑对象
    yqTextEditor: function (p_target, p_field) {
        var ed = null;
        var yqtype = p_target.data("yqtype");
        if (yqtype == "yqAttrEdit" || yqtype == "yqUiMaskEdit") {
            var r1 = p_target.propertygrid("getSelected");
            var i1 = p_target.propertygrid("getRowIndex", r1);
            p_target.propertygrid("beginEdit", i1)
            ed = p_target.propertygrid('getEditor', { index: i1, field: p_field });
        }
        else if (yqtype == "yqDataGrid") {
            var opt_ = p_target.yqDataGrid("options");
            p_target.datagrid("beginEdit", opt_.editIndex)
            ed = p_target.datagrid('getEditor', { index: opt_.editIndex, field: p_field });
        }
        else if (yqtype == "yqTableEdit") {
            var opt_ = p_target.datagrid("options");
            p_target.datagrid("beginEdit", opt_.editIndex)
            ed = p_target.datagrid('getEditor', { index: opt_.editIndex, field: p_field });
        } else if (yqtype == "yqTreeEdit") {
            var opt_ = p_target.treegrid("options");
            p_target.treegrid("beginEdit", opt_.editIndex)
            ed = p_target.treegrid('getEditor', { id: opt_.editIndex, field: p_field });
        } else {
            console.log("yqtype", p_target.data("yqtype"));
        }

        return ed;
    },
    //设置自定义编辑属性值
    yqDgEditorSetValue: function ($editor, val) {
        if ($editor.length == 0) {
            return;
        }

        var dg_type = $editor.data("dg_type");
        if (dg_type == "textbox") {
            $editor.textbox("setValue", val);
        } else if (dg_type == "checkbox") {
            $editor.checkbox("setValue", val);
        } else if (dg_type == "datebox") {
            $editor.datebox("setValue", val);
        } else if (dg_type == "yqTextRichBox") {
            $editor.yqTextRichBox("setValue", val);
        } else if (dg_type == "yqForeignKey") {
            $editor.yqForeignKey("setValue", val);
        } else if (dg_type == "combobox") {
            $editor.combobox("setValue", val);
        } else if (dg_type == "numberbox") {
            $editor.numberbox("setValue", val);
        } else if (dg_type == "numberspinner") {
            $editor.numberspinner("setValue", val);
        } else if (dg_type == "timespinner") {
            $editor.timespinner("setValue", val);
        } else if (dg_type == "datetimebox") {
            $editor.datetimebox("setValue", val);
        } else if (dg_type == "yqTextNCheckBox") {
            $editor.yqTextNCheckBox("setValue", val);
        } else if (dg_type == "yqNForeignKey") {
            $editor.yqNForeignKey("setValue", val);
        } else if (dg_type == "yqTextTable") {
            $editor.yqTextTable("setRows", val);
        } else if (dg_type == "yqTextTree") {
            $editor.yqTextTree("setData", val);
        } else if (dg_type == "yqTextAttr") {
            $editor.yqTextAttr("setRow", val);
        } else if (dg_type == "yqTextFilebox") {
            $editor.yqTextFilebox("setData", val);
        } else if (dg_type == "yqTextCSV") {
            $editor.yqTextCSV("setValue", val);
        } else if (dg_type == "yqTextFunc") {
            $editor.yqTextFunc("setValue", val);
        } else if (dg_type == "yqTextUiMask") {
            $editor.yqTextUiMask("setValue", val);
        } else if (dg_type == "yqTextTitles") {
            $editor.yqTextTitles("setValue", val);
        }
    },
    //获取自定义编辑属性值
    yqDgEditorGetValue: function ($editor) {
        if ($editor.length == 0) {
            return null;
        }

        var dg_type = $editor.data("dg_type");
        if (dg_type == "textbox") {
            return $editor.textbox("getValue");
        } else if (dg_type == "checkbox") {
            return $editor.checkbox("getValue");
        } else if (dg_type == "datebox") {
            return $editor.datebox("getValue");
        } else if (dg_type == "yqTextRichBox") {
            return $editor.yqTextRichBox("getValue");
        } else if (dg_type == "yqForeignKey") {
            return $editor.yqForeignKey("getValue");
        } else if (dg_type == "combobox") {
            return $editor.combobox("getValue");
        } else if (dg_type == "numberbox") {
            return $editor.numberbox("getValue");
        } else if (dg_type == "numberspinner") {
            return $editor.numberspinner("getValue");
        } else if (dg_type == "timespinner") {
            return $editor.timespinner("getValue");
        } else if (dg_type == "datetimebox") {
            return $editor.datetimebox("getValue");
        } else if (dg_type == "yqTextNCheckBox") {
            return $editor.yqTextNCheckBox("getValue");
        } else if (dg_type == "yqNForeignKey") {
            return $editor.yqNForeignKey("getValue");
        } else if (dg_type == "yqTextTable") {
            return $editor.yqTextTable("getRows");
        } else if (dg_type == "yqTextTree") {
            return $editor.yqTextTree("getData");
        } else if (dg_type == "yqTextAttr") {
            return $editor.yqTextAttr("getRow");
        } else if (dg_type == "yqTextFilebox") {
            return $editor.yqTextFilebox("getData");
        } else if (dg_type == "yqTextCSV") {
            return $editor.yqTextCSV("getValue");
        } else if (dg_type == "yqTextFunc") {
            return $editor.yqTextFunc("getValue");
        } else if (dg_type == "yqTextUiMask") {
            return $editor.yqTextUiMask("getValue");
        } else if (dg_type == "yqTextTitles") {
            return $editor.yqTextTitles("getValue");
        } else {
            return null;
        }
    }
});

//扩展datagrid编辑器
jQuery.extend(
    $.fn.datagrid.defaults.editors, {
    //ui_type=2
    dg_textbox: {
        init: function (container, options) {
            var input = $('<input type="text" \/>').appendTo(container);

            options.onChange_ = options.onChange;
            delete options.onChange;
            var para = $.yqGetDataGridByCell(container[0]);

            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;

            input.textbox(options);

            input.data("dg_type", "textbox");

            return input;
        },
        destroy: function (target) {
            $(target).textbox("destroy");
            $(target).remove();
        },
        getValue: function (target) {
            return $(target).textbox("getValue");
        },
        setValue: function (target, value) {
            if (value === undefined || typeof value === "") {
                value = null;
            }

            $(target).textbox("setValue", value);
            var options = $(target).textbox("options");
            options.onChange = function (newValue, oldValue) {
                options.onChange_.call(this, options.p_target, newValue);
            };
        },
        resize: function (target, width) {
            $(target).textbox("resize", width);
        }
    },
    //ui_type=3
    dg_checkbox: {
        init: function (container, options) {
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;
            var para = $.yqGetDataGridByCell(container[0]);
            var input = $('<input type="checkbox" \/>').appendTo(container);
            input.data("dg_opts", options);
            input.checkbox({
                checked: options.checked
            });
            input.next().css({
                "margin-left": "4px"
            });

            input.data("dg_type", "checkbox");

            return input;
        },
        destroy: function (target) {
            $(target).remove();
        },
        getValue: function (target) {
            return target.next().hasClass("checkbox-checked");
        },
        setValue: function (target, value) {
            if (value) {
                target.checkbox("check");
            } else {
                target.checkbox("uncheck");
            }

            var options = $(target).checkbox("options");
            options.onChange = function (checked) {
                var _opt = $(this).data("dg_opts");
                _opt.onChange.call(this, _opt.p_target, checked);
            };
        },
        resize: function (target, width) {
            //width = 20;
            //$(target)._outerWidth(width);
        }
    },
    //ui_type=4
    dg_datebox: {
        init: function (container, options) {
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;
            options.onChange_ = options.onChange;
            delete options.onChange;
            options._isload = false;
            options.onChange = function (newValue, oldValue) {
                var opt_ = $(this).datebox("options");
                if (opt_._isload) {
                    opt_.onChange_.call(this, opt_.p_target, newValue);
                }
            }

            options.parser = function (s) {
                if (s === undefined || s == "" || s === null) {
                    return null;
                }
                return $.convert_todate(s);
            };
            var input = $('<input type="text"/>').appendTo(container);
            input.datebox(options);

            input.data("dg_type", "datebox");

            return input;
        },
        destroy: function (target) {
            $(target).datebox("destroy");
            $(target).remove();
        },
        getValue: function (target) {
            var value = $(target).datebox("getValue");
            if (value == "") {
                value = null;
            }
            if (value != null) {
                value = $.convert_todate(value);
            }
            return value;
        },
        setValue: function (target, value) {
            if (!(value === null)) {
                target.datebox("setValue", value);
            }
            var opt_ = target.datebox("options");
            opt_._isload = true;
        },
        resize: function (target, width) {
            $(target).datebox("resize", width);
        }
    },
    //ui_type=5
    dg_richbox: {
        init: function (container, options) {
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;

            var input = $('<input type="text" \/>').appendTo(container);
            input.yqTextRichBox(options);

            input.data("dg_type", "yqTextRichBox");

            return input;
        },
        destroy: function (target) {
            $(target).yqTextRichBox("destroy");
            $(target).remove();
        },
        getValue: function (target) {
            return $(target).yqTextRichBox("getValue");
        },
        setValue: function (target, value) {
            target.yqTextRichBox("setValue", value);
            var options = target.yqTextRichBox("options");
            options.afterChange = function (val) {
                options.onChange.call(this, options.p_target, val);
            }
        },
        resize: function (target, width) {
            $(target).yqTextRichBox("resize", width);
        }
    },
    //ui_type=6
    dg_combobox: {
        init: function (container, options) {
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;

            options.onChange_ = options.onChange;
            delete options.onChange;

            options.loading = false;
            options.onChange = function (newValue, oldValue) {
                var opt = $(this).combobox("options");
                if (opt.loading) {
                    opt.onChange_.call(this, opt.p_target, newValue);
                }
            };

            options.editable = false;
            options.valueField = "no";
            options.textField = "name";
            options.panelHeight = 'auto';
            options.panelMaxHeight = 154;
            var data = [];

            var b_row = { "no": (options.type == "string" ? "" : -1), "name": $.fn.yqUiExtText.ComboboxBlankText };
            data.push(b_row);
            for (let i = 0; i < options.data.length; i++) {
                data.push($.extend({}, options.data[i]));
            }
            options.data = data;

            var input = $('<select/>').appendTo(container);
            input.combobox(options);

            input.data("dg_type", "combobox");

            return input;
        },
        destroy: function (target) {
            $(target).combobox("destroy");
            $(target).remove();
        },
        getValue: function (target) {
            var value = $(target).combobox("getValue");
            if (value === undefined) {
                value = null;
            }
            var opt_ = $(target).combobox("options");
            if (opt_.type == "string") {
                if (value == "") {
                    value = null;
                }
            } else {
                value = $.yqToInt(value);
                if (value == -1) {
                    value = null;
                }
            }
            return value;
        },
        setValue: function (target, value) {
            if (value === undefined) {
                value = null;
            }
            var opt_ = $(target).combobox("options");
            if (opt_.type == "string") {
                if (value === null) {
                    value = "";
                }
            } else {
                value = $.yqToInt(value);
                if (value === null) {
                    value = -1;
                }
            }

            $(target).combobox("setValue", value);

            var options = target.combobox("options");
            options.loading = true;
        },
        resize: function (target, width) {
            $(target).combobox("resize", width);
        }
    },
    //ui_type=7
    dg_foreignkey: {
        init: function (container, options) {
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;

            //console.log(options);

            var p_opt;
            var yqtype = para.target.data("yqtype");
            if (yqtype == "yqDataGrid") {
                p_opt = para.target.yqDataGrid("options");
            } else if (yqtype == "yqAttrEdit") {
                p_opt = para.target.yqAttrEdit("options");
            } else if (yqtype == "yqTableEdit") {
                p_opt = para.target.yqTableEdit("options");
            } else if (yqtype == "yqTreeEdit") {
                p_opt = para.target.yqTreeEdit("options");
            } else if (yqtype == "yqUiMaskEdit") {
                p_opt = para.target.yqUiMaskEdit("options");
            }

            // var p_opt;
            // if (options.pedit.type == "datagrid") {
            //     p_opt = options.pedit.target.yqDataGrid("options");
            // }
            // else if (options.pedit.type == "datagrid") {
            //     p_opt = options.pedit.target.propertygrid("options");
            // }

            if (typeof p_opt != "undefined") {
                options.ajaxUrl = p_opt.ajaxUrl;
            }

            if (options.ajaxUrl === null || options.ajaxUrl == "") {
                delete options.ajaxUrl;
            }

            var input = $('<select/>').appendTo(container);
            input.yqForeignKey(options);

            input.data("dg_type", "yqForeignKey");

            return input;
        },
        destroy: function (target) {
            $(target).yqForeignKey("destroy");
            $(target).remove();
        },
        getValue: function (target) {
            var row = $(target).yqForeignKey("getRow");

            if (row != null) {
                var para = $.yqGetDataGridByCell(target[0]);
                var p_opt;
                var yqtype = para.target.data("yqtype");
                var field;
                var valueMember = $(target).yqForeignKey("options").valueMember;
                if (yqtype == "yqDataGrid") {
                    p_opt = para.target.yqDataGrid("options");
                    field = para.field;
                } else if (yqtype == "yqAttrEdit") {
                    p_opt = para.target.yqAttrEdit("options");
                    field = para.target.propertygrid("getSelected").field;
                } else if (yqtype == "yqTableEdit") {
                    p_opt = para.target.yqTableEdit("options");
                    field = para.field;
                } else if (yqtype == "yqTreeEdit") {
                    p_opt = para.target.yqTreeEdit("options");
                    field = para.field;
                } else if (yqtype == "yqUiMaskEdit") {
                    p_opt = para.target.yqUiMaskEdit("options");
                    field = para.target.propertygrid("getSelected").field;
                }

                var fk_rows = p_opt.fk_rows === undefined ? [] : p_opt.fk_rows
                var has_row = false;
                for (let i = 0; i < fk_rows.length; i++) {
                    if (field == fk_rows[i].field) {
                        var var_len = false;
                        for (let j = 0; j < fk_rows[i].rows.length; j++) {
                            if (fk_rows[i].rows[j][valueMember] == row[valueMember]) {
                                var_len = true;
                                break;
                            }
                        }

                        if (!var_len) {
                            fk_rows[i].rows.push(row);
                        }

                        has_row = true;
                        break;
                    }
                }
                if (!has_row) {
                    fk_rows.push({ field: field, rows: [row] });
                }

                p_opt.fk_rows = fk_rows;
            }

            var value = $(target).yqForeignKey("getValue");
            return value;
        },
        setValue: function (target, value) {
            $(target).yqForeignKey("setValue", value);

            var options = target.yqForeignKey("options");
            options.onClickRow = function (rowIndex, rowData) {
                var yqtype = options.p_target.data("yqtype");
                for (var i = 0; i < options.mapping.length; i++) {
                    var val = null;
                    if (!(rowData === null)) {
                        val = rowData[options.mapping[i].from];
                        if (val === undefined) {
                            val = null;
                        }
                    }

                    if (yqtype == "yqDataGrid") {
                        options.p_target.yqDataGrid("setField", {
                            name: options.mapping[i].to,
                            value: val
                        });
                    } else if (yqtype == "yqAttrEdit") {
                        options.p_target.yqAttrEdit("setField", {
                            name: options.mapping[i].to,
                            value: val
                        });
                    } else if (yqtype == "yqTableEdit") {
                        options.p_target.yqTableEdit("setField", {
                            name: options.mapping[i].to,
                            value: val
                        });
                    } else if (yqtype == "yqTreeEdit") {
                        options.p_target.yqTreeEdit("setField", {
                            name: options.mapping[i].to,
                            value: val
                        });
                    } else if (yqtype == "yqUiMaskEdit") {
                        options.p_target.yqUiMaskEdit("setField", {
                            name: options.mapping[i].to,
                            value: val
                        });
                    }
                }

                options.onChange.call(this, options.p_target, rowData);
            }
        },
        resize: function (target, width) {
            $(target).yqForeignKey("resize", width);
        }
    },
    //ui_type=8
    dg_combobox_tree: {
        init: function (container, options) {
            options.editable = false;
            options.valueField = "no";
            options.textField = "name";
            options.panelHeight = 'auto';
            options.panelMaxHeight = 154;

            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;

            options.onChange_ = options.onChange;
            delete options.onChange;

            var data = [];
            data.push({ "no": (options.type == "string" ? "" : -1), "name": $.fn.yqUiExtText.ComboboxBlankText });
            for (let i = 0; i < options.data.length; i++) {
                data.push($.extend({}, options.data[i]));
            }
            options.data = data;

            options._isload = false;

            if (options.subfield != null && para.target.data("yqtype") == "yqDataGrid") {
                options.onChange = function (newValue, oldValue) {
                    var opt_ = $(this).combobox("options");

                    if (opt_._isload) {
                        opt_.onChange_.call(this, opt_.p_target, newValue);
                    }

                    var runRow = opt_.p_target.datagrid("options").editRunRow;
                    var runValue = runRow[opt_.p_field];
                    runValue = $.yqToInt(runValue);
                    if (runValue === null) {
                        runValue = -1;
                    }

                    if (opt_._isload || (opt_._isload === undefined && newValue != runValue)) {
                        opt_._load = true;
                        var c_editor = opt_.p_target.datagrid("getEditor",
                            {
                                index: opt_.p_target.datagrid("options").editRunIndex,
                                field: opt_.subfield
                            });

                        if (c_editor === null) {
                            return;
                        }

                        c_editor.target.combobox("options").onSetValue.call(c_editor.target, $(this), newValue, -1);
                    }
                    else {
                        opt_._isload = true;
                    }

                };
            } else {
                options.onChange = function (newValue, oldValue) {
                    var opt_ = $(this).combobox("options");
                    if (opt_._isload) {
                        opt_.onChange_.call(this, opt_.p_target, newValue);
                    }
                    opt_._isload = true;
                };
            }

            //值，初始化赋值，父项值
            options.onSetValue = function (p_combobox, p_value, value) {
                var opt = $(this).combobox("options");
                p_value = $.yqToInt(p_value);
                if (p_value === null) {
                    p_value = -1;
                }
                value = $.yqToInt(value);
                if (value === null) {
                    value = -1;
                }

                var lists = [];
                lists.push({ no: -1, name: $.fn.yqUiExtText.ComboboxBlankText });
                if (p_value != -1) {
                    var p_data = p_combobox.combobox("getData");
                    for (let i = 0; i < p_data.length; i++) {
                        if (p_data[i].no == p_value) {
                            if (p_data[i].subs === undefined) {
                                p_data[i].subs = [];
                            }

                            for (let j = 0; j < p_data[i].subs.length; j++) {
                                lists.push($.extend({}, p_data[i].subs[j]));
                            }

                            break;
                        }
                    }
                }

                $(this).combobox("loadData", lists);
                var hasss = false;
                for (var i = 0; i < lists.length; i++) {
                    if (lists[i].no == value) {
                        hasss = true;
                        break;
                    }
                }
                if (!hasss) {
                    value = -1;
                }

                $(this).combobox("setValue", value);
            };

            var input = $('<select/>').appendTo(container);
            input.combobox(options);

            input.data("dg_type", "combobox");

            return input;
        },
        destroy: function (target) {
            $(target).combobox("destroy");
            $(target).remove();
        },
        getValue: function (target) {
            var value = $(target).combobox("getValue");
            if (value === undefined) {
                value = null;
            }

            var _opt = $(target).combobox("options");
            if (_opt.type == "string") {
                if (value == "") {
                    value = null;
                }
            } else {
                value = $.yqToInt(value);
                if (value == -1) {
                    value = null;
                }
            }

            return value;
        },
        setValue: function (target, value) {
            if (value === undefined) {
                value = null;
            }

            var options = target.combobox("options");
            if (options.type == "string") {
                if (value === null) {
                    value = "";
                }
            } else {
                value = $.yqToInt(value);
                if (value === null) {
                    value = -1;
                }
            }

            if (options.level == 1) {
                $(target).combobox("setValue", value);
                return;
            }

            var yqtype = options.p_target.data("yqtype");
            if (yqtype == "yqDataGrid") {
                var editors = options.p_target.datagrid("getEditors", options.p_target.datagrid("options").editRunIndex);

                for (var p = 0; p < editors.length; p++) {
                    if (editors[p].type == "dg_combobox_tree") {
                        var opt_ = editors[p].target.combobox("options");
                        if (opt_.subfield == options.p_field) {
                            opt_._isload = true;

                            options.onSetValue.call(target, editors[p].target,
                                editors[p].target.combobox("getValue"), value);

                            break;
                        }
                    }
                }
            }
            else if (yqtype == "yqAttrEdit") {
                var p_opt = options.p_target.yqAttrEdit("options");

                var p_rows = options.p_target.datagrid("getRows");
                var subfield = p_rows[options.p_rowindex].field;

                var trees = [];
                var p_level = 1;
                var p_value = -1;
                if (options.type == "string") {
                    p_value = "";
                }

                for (let i = 0; i < p_opt.titles.length; i++) {
                    if (p_opt.titles[i].ui_type == 8 && p_opt.titles[i].ui_mask.subfield == subfield) {
                        trees = p_opt.titles[i].ui_mask.trees;
                        p_level = p_opt.titles[i].ui_mask.level;
                        for (let j = 0; j < p_rows.length; j++) {
                            if (p_rows[j].field == p_opt.titles[i].name) {
                                p_value = p_rows[j].value;
                                if (options.type == "string") {
                                    if (p_value === null) {
                                        p_value = "";
                                    }
                                } else {
                                    if (p_value === null) {
                                        p_value = -1;
                                    }
                                    else {
                                        p_value = parseInt(p_value);
                                        if (isNaN(p_value)) {
                                            p_value = -1;
                                        }
                                    }
                                }
                                break;
                            }
                        }

                        break;
                    }
                }

                var lists = [];
                if (options.type == "string") {
                    if (p_value == "") {
                        lists.push({ no: "", name: $.fn.yqUiExtText.ComboboxBlankText });
                    }
                    else {
                        lists = get_fk_lists(1, p_level, trees, p_value);
                    }
                } else {
                    if (p_value == -1) {
                        lists.push({ no: -1, name: $.fn.yqUiExtText.ComboboxBlankText });
                    }
                    else {
                        lists = get_fk_lists(1, p_level, trees, p_value);
                    }
                }

                target.combobox("loadData", lists);
                var hasss = false;
                for (var i = 0; i < lists.length; i++) {
                    if (lists[i].no == value) {
                        hasss = true;
                        break;
                    }
                }
                if (!hasss) {
                    if (options.type == "string") {
                        value = "";
                    } else {
                        value = -1;
                    }
                }

                target.combobox("setValue", value);

                function get_fk_lists(level, p_level, trees, p_value) {
                    for (var l = 0; l < trees.length; l++) {
                        if (level < p_level) {
                            var tval = get_fk_lists(level + 1, p_level, trees[l].subs, p_value);
                            if (tval.length > 0) {
                                return tval;
                            }
                        }
                        else if (level == p_level) {
                            if (trees[l].no == p_value) {
                                var lists = [];
                                lists.push({ no: (options.type == "string" ? "" : -1), name: $.fn.yqUiExtText.ComboboxBlankText });
                                if (trees[l].subs === undefined) {
                                    trees[l].subs = [];
                                }
                                for (var i = 0; i < trees[l].subs.length; i++) {
                                    lists.push({ "no": trees[l].subs[i].no, "name": trees[l].subs[i].name });
                                }

                                return lists;
                                break;
                            }
                        }
                    }

                    return [];
                }
            }
        },
        resize: function (target, width) {
            $(target).combobox("resize", width);
        }
    },
    //ui_type=9
    dg_numberbox: {
        init: function (container, options) {
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;
            options.onChange_ = options.onChange;
            delete options.onChange;
            options._isload = false;
            options.onChange = function (newValue, oldValue) {
                var opt_ = $(this).numberbox("options");
                if (opt_._isload) {
                    opt_.onChange_.call(this, opt_.p_target, newValue);
                }
            }

            var input = $('<input type="text"/>').appendTo(container);
            input.numberbox(options);

            input.data("dg_type", "numberbox");

            return input;
        },
        destroy: function (target) {
            $(target).numberbox("destroy");
            $(target).remove();
        },
        getValue: function (target) {
            var value = $(target).numberbox("getValue");
            if (value != null) {
                value = Number(value);
                if (isNaN(value)) {
                    value = null;
                }
            }

            return value;
        },
        setValue: function (target, value) {
            $(target).numberbox("setValue", value);

            var opt_ = target.numberbox("options");
            opt_._isload = true;
        },
        resize: function (target, width) {
            $(target).numberbox("resize", width);
        }
    },
    //ui_type=10
    dg_numberspinner: {
        init: function (container, options) {
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;
            options.onChange_ = options.onChange;
            delete options.onChange;
            options._isload = false;
            options.onChange = function (newValue, oldValue) {
                var opt_ = $(this).numberspinner("options");
                if (opt_._isload) {
                    opt_.onChange_.call(this, opt_.p_target, newValue);
                }
            }

            var input = $('<input type="text"/>').appendTo(container);
            input.numberspinner(options);

            input.data("dg_type", "numberspinner");

            return input;
        },
        destroy: function (target) {
            $(target).numberspinner("destroy");
            $(target).remove();
        },
        getValue: function (target) {
            var value = $(target).numberspinner("getValue");
            if (value != null) {
                value = parseInt(value);
                if (isNaN(value)) {
                    value = null;
                }
            }
            return value;
        },
        setValue: function (target, value) {
            $(target).numberspinner("setValue", value);

            var opt_ = target.numberspinner("options");
            opt_._isload = true;
        },
        resize: function (target, width) {
            $(target).numberspinner("resize", width);
        }
    },
    //ui_type=11
    dg_timespinner: {
        init: function (container, options) {
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;
            options.onChange_ = options.onChange;
            delete options.onChange;
            options._isload = false;
            options.onChange = function (newValue, oldValue) {
                var opt_ = $(this).timespinner("options");
                if (opt_._isload) {
                    opt_.onChange_.call(this, opt_.p_target, newValue);
                }
            }

            var input = $('<input type="text"/>').appendTo(container);
            input.timespinner(options);

            input.data("dg_type", "timespinner");

            return input;
        },
        destroy: function (target) {
            $(target).timespinner("destroy");
            $(target).remove();
        },
        getValue: function (target) {
            var value = $(target).timespinner("getValue");
            if (value == "") {
                value = null;
            }
            return value;
        },
        setValue: function (target, value) {
            if (value === null) {
                var opt_ = target.timespinner("options");
                opt_._isload = true;
                return;
            }
            $(target).timespinner("setValue", value);
            var opt_ = target.timespinner("options");
            opt_._isload = true;
        },
        resize: function (target, width) {
            $(target).timespinner("resize", width);
        }
    },
    //ui_type=12
    dg_datetimebox: {
        init: function (container, options) {
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;
            options.onChange_ = options.onChange;
            delete options.onChange;
            options._isload = false;
            options.onChange = function (newValue, oldValue) {
                var opt_ = $(this).datetimebox("options");
                if (opt_._isload) {
                    opt_.onChange_.call(this, opt_.p_target, newValue);
                }
            }

            var input = $('<input type="text"/>').appendTo(container);
            input.datetimebox(options);

            input.data("dg_type", "datetimebox");

            return input;
        },
        destroy: function (target) {
            $(target).datetimebox("destroy");
            $(target).remove();
        },
        getValue: function (target) {
            var value = $(target).datetimebox("getValue");
            if (value == "") {
                value = null;
            }
            if (value != null) {
                value = $.convert_todate(value);
            }
            return value;
        },
        setValue: function (target, value) {
            if (value === null) {
                var opt_ = target.datetimebox("options");
                opt_._isload = true;
                return;
            }
            $(target).datetimebox("setValue", value);
            var opt_ = target.datetimebox("options");
            opt_._isload = true;
        },
        resize: function (target, width) {
            $(target).datetimebox("resize", width);
        }
    },
    //ui_type=13
    dg_ncombobox: {
        init: function (container, options) {
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;

            var input = $('<input type="text" \/>').appendTo(container);
            input.yqTextNCheckBox(options);

            input.data("dg_type", "yqTextNCheckBox");

            return input;
        },
        destroy: function (target) {
            $(target).yqTextNCheckBox("destroy");
            $(target).remove();
        },
        getValue: function (target) {
            return $(target).yqTextNCheckBox("getValue");
        },
        setValue: function (target, value) {
            target.yqTextNCheckBox("setValue", value);
            var options = target.yqTextNCheckBox("options");
            options.afterChange = function (val) {
                options.onChange.call(this, options.p_target, val);
            }
        },
        resize: function (target, width) {
            $(target).yqTextNCheckBox("resize", width);
        }
    },
    //ui_type=14
    dg_nforeignkey: {
        init: function (container, options) {
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;

            //console.log(options);

            var p_opt;
            var yqtype = para.target.data("yqtype");
            if (yqtype == "yqDataGrid") {
                p_opt = para.target.yqDataGrid("options");
            } else if (yqtype == "yqAttrEdit") {
                p_opt = para.target.yqAttrEdit("options");
            } else if (yqtype == "yqTableEdit") {
                p_opt = para.target.yqTableEdit("options");
            } else if (yqtype == "yqTreeEdit") {
                p_opt = para.target.yqTreeEdit("options");
            }

            // var p_opt;
            // if (options.pedit.type == "datagrid") {
            //     p_opt = options.pedit.target.yqDataGrid("options");
            // }
            // else if (options.pedit.type == "datagrid") {
            //     p_opt = options.pedit.target.propertygrid("options");
            // }

            if (typeof p_opt != "undefined") {
                options.ajaxUrl = p_opt.ajaxUrl;
                // if (typeof p_opt["opt_fktitles_" + options.ui_mask.valueMember] != "undefined") {
                //     options.titles = p_opt["opt_fktitles_" + options.ui_mask.valueMember];
                // }
            }

            if (options.ajaxUrl === null || options.ajaxUrl == "") {
                delete options.ajaxUrl;
            }

            var input = $('<select/>').appendTo(container);
            input.yqNForeignKey(options);

            input.data("dg_type", "yqNForeignKey");

            return input;
        },
        destroy: function (target) {
            $(target).yqNForeignKey("destroy");
            $(target).remove();
        },
        getValue: function (target) {
            var rows = $(target).yqNForeignKey("getRows");
            if (rows.length > 0) {
                var para = $.yqGetDataGridByCell(target[0]);
                var p_opt;
                var yqtype = para.target.data("yqtype");
                var field;
                var valueMember = $(target).yqNForeignKey("options").valueMember;

                if (yqtype == "yqDataGrid") {
                    p_opt = para.target.yqDataGrid("options");
                    field = para.field;
                } else if (yqtype == "yqAttrEdit") {
                    p_opt = para.target.yqAttrEdit("options");
                    field = para.target.propertygrid("getSelected").field;
                } else if (yqtype == "yqTableEdit") {
                    p_opt = para.target.yqTableEdit("options");
                    field = para.field;
                } else if (yqtype == "yqTreeEdit") {
                    p_opt = para.target.yqTreeEdit("options");
                    field = para.field;
                } else if (yqtype == "yqUiMaskEdit") {
                    p_opt = para.target.yqUiMaskEdit("options");
                    field = para.target.propertygrid("getSelected").field;
                }

                var fk_rows = p_opt.fk_rows === undefined ? [] : p_opt.fk_rows

                for (let j = 0; j < rows.length; j++) {
                    const row = rows[j];
                    var has_row = false;
                    for (let i = 0; i < fk_rows.length; i++) {
                        if (field == fk_rows[i].field) {
                            var var_len = false;
                            for (let j = 0; j < fk_rows[i].rows.length; j++) {
                                if (fk_rows[i].rows[j][valueMember] == row[valueMember]) {
                                    var_len = true;
                                    break;
                                }
                            }

                            if (!var_len) {
                                fk_rows[i].rows.push(row);
                            }

                            has_row = true;
                            break;
                        }
                    }
                    if (!has_row) {
                        fk_rows.push({ field: field, rows: [row] });
                    }
                }

                p_opt.fk_rows = fk_rows;
            }

            var value = $(target).yqNForeignKey("getValue");
            return value;
        },
        setValue: function (target, value) {
            $(target).yqNForeignKey("setValue", value);
            var options = target.yqNForeignKey("options");
            options.onClickRow = function (rows) {
                var yqtype = options.p_target.data("yqtype");
                for (var i = 0; i < options.mapping.length; i++) {
                    var val = null;
                    if (!(rows === null)) {
                        for (var j = 0; j < rows.length; j++) {
                            var _val = rows[j][options.mapping[i].from];
                            if (!(_val === undefined)) {
                                if (val === null) {
                                    val = _val;
                                } else {
                                    val += ("," + _val);
                                }
                            }
                        }
                    }

                    if (yqtype == "yqDataGrid") {
                        options.p_target.yqDataGrid("setField", {
                            name: options.mapping[i].to,
                            value: val
                        });
                    } else if (yqtype == "yqAttrEdit") {
                        options.p_target.yqAttrEdit("setField", {
                            name: options.mapping[i].to,
                            value: val
                        });
                    } else if (yqtype == "yqTableEdit") {
                        options.p_target.yqTableEdit("setField", {
                            name: options.mapping[i].to,
                            value: val
                        });
                    } else if (yqtype == "yqTreeEdit") {
                        options.p_target.yqTreeEdit("setField", {
                            name: options.mapping[i].to,
                            value: val
                        });
                    } else if (yqtype == "yqUiMaskEdit") {
                        options.p_target.yqUiMaskEdit("setField", {
                            name: options.mapping[i].to,
                            value: val
                        });
                    }
                }

                options.onChange.call(this, options.p_target, rows);
            }
        },
        resize: function (target, width) {
            $(target).yqNForeignKey("resize", width);
        }
    },
    //ui_type=15
    dg_texttable: {
        init: function (container, options) {
            //console.log("edit_options", options);
            var input = $('<input type="text" \/>').appendTo(container);
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;

            if (options.ajaxUrl === null || options.ajaxUrl == "") {
                delete options.ajaxUrl;
            }

            input.yqTextTable(options);

            input.data("dg_type", "yqTextTable");

            return input;
        },
        destroy: function (target) {
            target.yqTextTable("destroy");
            target.remove();
        },
        getValue: function (target) {
            return target.yqTextTable("getRows");
        },
        setValue: function (target, value) {
            target.yqTextTable("setRows", value);

            var options = target.yqTextTable("options");
            options._afterChange = options.afterChange;
            options.afterChange = function (rows) {
                options._afterChange.call(this, rows);
                options.onChange.call(this, options.p_target, rows);
            }
        },
        resize: function (target, width) {
            target.yqTextTable("resize", width);
        }
    },
    //ui_type=16
    dg_texttree: {
        init: function (container, options) {
            //console.log("edit_options", options);
            var input = $('<input type="text" \/>').appendTo(container);
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;

            if (options.ajaxUrl === null || options.ajaxUrl == "") {
                delete options.ajaxUrl;
            }

            input.yqTextTree(options);

            input.data("dg_type", "yqTextTree");

            return input;

            function getDataGridFieldName(el) {
                var target = $(el).closest('div.datagrid-cell');
                return target.closest("td").attr("field");
            }

            function getDataGridTarget(el) {
                //oceandeng 兼容处理bug
                var target = $(el).closest('div.datagrid-view');
                if (target.children('table').length > 0) {
                    return target.children('table');
                }
                else {
                    return target.children(".datagrid-f");
                }
            }
        },
        destroy: function (target) {
            target.yqTextTree("destroy");
            target.remove();
        },
        getValue: function (target) {
            return target.yqTextTree("getData");
        },
        setValue: function (target, value) {
            target.yqTextTree("setData", value);

            var options = target.yqTextTree("options");
            options._afterChange = options.afterChange;
            options.afterChange = function (rows) {
                options._afterChange.call(this, rows);
                options.onChange.call(this, options.p_target, rows);
            }
        },
        resize: function (target, width) {
            target.yqTextTree("resize", width);
        }
    },
    //ui_type=17
    dg_textattr: {
        init: function (container, options) {
            //console.log("edit_options", options);
            var input = $('<input type="text" \/>').appendTo(container);
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;

            if (options.ajaxUrl === null || options.ajaxUrl == "") {
                delete options.ajaxUrl;
            }

            input.yqTextAttr(options);

            input.data("dg_type", "yqTextAttr");

            return input;
        },
        destroy: function (target) {
            target.yqTextAttr("destroy");
            target.remove();
        },
        getValue: function (target) {
            return target.yqTextAttr("getRow");
        },
        setValue: function (target, value) {
            target.yqTextAttr("setRow", value);

            var options = target.yqTextAttr("options");
            options._afterChange = options.afterChange;
            options.afterChange = function (row) {
                options._afterChange.call(this, row);
                options.onChange.call(this, options.p_target, row);
            }
        },
        resize: function (target, width) {
            target.yqTextAttr("resize", width);
        }
    },
    //ui_type=18 file
    dg_filebox: {
        init: function (container, options) {
            var input = $('<input type="text" \/>').appendTo(container);
            if (options.ajaxUrl === null || options.ajaxUrl == "") {
                delete options.ajaxUrl;
            }
            input.yqTextFilebox(options);

            input.data("dg_type", "yqTextFilebox");

            return input;
        },
        destroy: function (target) {
            $(target).yqTextFilebox("destroy");
            $(target).remove();
        },
        getValue: function (target) {
            return $(target).yqTextFilebox("getData");
        },
        setValue: function (target, value) {
            $(target).yqTextFilebox("setData", value);

            //todo 没有此事件
            //     var options = target.yqTextFilebox("options");
            //     options.afterChange = function (row) {
            //         options.onChange.call(this, options.p_target, row);
            //     }
        },
        resize: function (target, width) {
            $(target).yqTextFilebox("resize", width);
        }
    },
    //ui_type=19 html
    dg_richedit: {
        init: function (container, options) {
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;
            if (options.ajaxUrl === null || options.ajaxUrl == "") {
                delete options.ajaxUrl;
            }

            if (options.storageType == 1) {
                var p_opt;
                var yqtype = para.target.data("yqtype");
                if (yqtype == "yqDataGrid") {
                    p_opt = para.target.yqDataGrid("options");
                } else if (yqtype == "yqAttrEdit") {
                    p_opt = para.target.yqAttrEdit("options");
                }

                if (typeof p_opt.dbname == "string") {
                    options.storageName = p_opt.dbname;
                }
            }

            var input = $('<input type="text" \/>').appendTo(container);
            input.yqTextRichEdit(options);

            input.data("dg_type", "yqTextRichEdit");

            return input;
        },
        destroy: function (target) {
            $(target).yqTextRichEdit("destroy");
            $(target).remove();
        },
        getValue: function (target) {
            return $(target).yqTextRichEdit("getData");
        },
        setValue: function (target, value) {
            $(target).yqTextRichEdit("setData", value);

            //todo
            // var options = target.yqTextRichEdit("options");
            // options.afterChange = function (row) {
            //     options.onChange.call(this, options.p_target, row);
            // }
        },
        resize: function (target, width) {
            $(target).yqTextRichEdit("resize", width);
        }
    },
    //ui_type=20
    dg_textcsv: {
        init: function (container, options) {
            //console.log("edit_options", options);
            var input = $('<input type="text" \/>').appendTo(container);
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;

            input.yqTextCSV(options);

            input.data("dg_type", "yqTextCSV");

            return input;
        },
        destroy: function (target) {
            target.yqTextCSV("destroy");
            target.remove();
        },
        getValue: function (target) {
            return target.yqTextCSV("getValue");
        },
        setValue: function (target, value) {
            target.yqTextCSV("setValue", value);

            var options = target.yqTextCSV("options");
            options._afterChange = options.afterChange;
            options.afterChange = function (value) {
                options._afterChange.call(this, value);
                options.onChange.call(this, options.p_target, value);
            }
        },
        resize: function (target, width) {
            target.yqTextCSV("resize", width);
        }
    },
    //ui_type=21
    dg_textfunc: {
        init: function (container, options) {
            //console.log("edit_options", options);
            var input = $('<input type="text" \/>').appendTo(container);
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;

            input.yqTextFunc(options);

            input.data("dg_type", "yqTextFunc");

            return input;
        },
        destroy: function (target) {
            target.yqTextFunc("destroy");
            target.remove();
        },
        getValue: function (target) {
            return target.yqTextFunc("getValue");
        },
        setValue: function (target, value) {
            target.yqTextFunc("setValue", value);

            var options = target.yqTextFunc("options");
            options._afterChange = options.afterChange;
            options.afterChange = function (value) {
                options._afterChange.call(this, value);
                options.onChange.call(this, options.p_target, value);
            }
        },
        resize: function (target, width) {
            target.yqTextFunc("resize", width);
        }
    },
    //ui_type=900 mask 编辑
    dg_ui_mask: {
        init: function (container, options) {
            var input = $('<input type="text" \/>').appendTo(container);
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;

            input.yqTextUiMask(options);

            input.data("dg_type", "yqTextUiMask");

            return input;
        },
        destroy: function (target) {
            target.yqTextUiMask("destroy");
            target.remove();
        },
        getValue: function (target) {
            return target.yqTextUiMask("getValue");
        },
        setValue: function (target, value) {
            target.yqTextUiMask("setValue", value);

            var options = target.yqTextUiMask("options");
            options._afterChange = options.afterChange;
            options.afterChange = function (rows) {
                options._afterChange.call(this, rows);
                options.onChange.call(this, options.p_target, rows);
            }
        },
        resize: function (target, width) {
            target.yqTextAttr("resize", width);
        }
    },
    //ui_type=901 titles 编辑
    dg_titlesedit: {
        init: function (container, options) {

            //console.log("edit_options", options);
            var input = $('<input type="text" \/>').appendTo(container);
            var para = $.yqGetDataGridByCell(container[0]);
            options.p_field = para.field;
            options.p_target = para.target;
            options.p_rowindex = para.rowindex;
            if (options.ajaxUrl === null || options.ajaxUrl == "") {
                delete options.ajaxUrl;
            }
            input.yqTextTitles(options);

            input.data("dg_type", "yqTextTitles");

            return input;
        },
        destroy: function (target) {
            target.yqTextTitles("destroy");
            target.remove();
        },
        getValue: function (target) {
            return target.yqTextTitles("getValue");
        },
        setValue: function (target, value) {
            target.yqTextTitles("setValue", value);

            //todo
            // var options = target.yqTextTitles("options");
            // options.afterChange = function (row) {
            //     options.onChange.call(this, options.p_target, row);
            // }
        },
        resize: function (target, width) {
            target.yqTextTitles("resize", width);
        }
    },
});

// 弹框相关
jQuery.extend({
    //弹出模态窗体,包含关闭按钮
    yqDialog: function (options) {
        var opt = $.extend({
            prevent_e: {      //调用组件信息
                clientX: 0,
                clientY: 0
            },
            mdiinfo: {            //mdi窗体信息
                clientX: 0,
                clientY: 0
            },
            showTitle: true,
            title: "Dialog",
            width: 600,
            height: 400,
            horizontalAlign: "none",    //left,right,center,none
            verticalAlign: "none",      //top,bottom,center,none
            buttons: [],
            closeBtn: true,
            closeBtnText: $.fn.yqUiExtText.btnNo,
            iframe: false,
            iframeUrl: "",
            iconCls: "",
            onOpen: function ($body) {
                //console.log("$body", $body);
            },
            onResize: function (width, height) {
                //console.log("onResize", width, height);
            },
            onBeforeClose: function () {
                return true;
            },
            onClose: function () {
            }
        }, options);

        var $dg = $('<div></div>');
        $("body").append($dg);

        var $body;

        opt.onload = false;
        var dg_opt = {
            noheader: !opt.showTitle,
            title: opt.title,
            width: opt.width,
            height: opt.height,
            closed: false,
            cache: false,
            prevent_e: opt.prevent_e,
            onOpen: function () {
                $body = $(this).dialog("body");
                $body.attr("id", $.getUniqueID());

                if (opt.iframe) {

                    $body.css({
                        padding: 0,
                        margin: 0,
                        overflow: "hidden"
                    });
                    var iframeid = $.getKeyAdd();
                    var w = $body.width();
                    var h = $body.height();

                    var iframeUrl = opt.iframeUrl;
                    if (/[?&]/.test(iframeUrl)) {
                        iframeUrl += '&iframenum=' + iframeid;
                    }
                    else {
                        iframeUrl += '?iframenum=' + iframeid;
                    }
                    var $iframe = $('<iframe id="iframe_' + iframeid + '" style="width:' + w + 'px;height:' + h + 'px;" src="' + iframeUrl + '"></iframe>');
                    $iframe.data("prevent_e", opt.prevent_e);
                    $iframe.data("$dg", $dg);

                    $body.append($iframe);
                }

                opt.onOpen.call(this, $body);
            },
            onResize: function (width, height) {
                opt.onResize.call(this, width, height);
            },
            onBeforeClose: function () {
                return opt.onBeforeClose.call(this); //return false 会阻止dialog clos 
            },
            onClose: function () {
                opt.onClose.call(this);
                try {
                    $(this).dialog("destroy");
                    $(this).remove();
                } catch (error) {
                    console.log(error);
                }
            },
            modal: true
        };

        if (typeof opt.iconCls == "string" && opt.iconCls != "") {
            dg_opt.iconCls = opt.iconCls;
        }

        var buttons = [];
        for (let i = 0; i < opt.buttons.length; i++) {
            var btn = $.extend({}, opt.buttons[i]);
            btn.id = $.getUniqueID();
            opt.buttons[i].id = btn.id;
            btn.onClick = function () {
                var id_ = $(this).attr("id");
                for (let j = 0; j < opt.buttons.length; j++) {
                    if (opt.buttons[j].id == id_) {
                        opt.buttons[j].onClick.call($dg, $body);
                        break;
                    }
                }
            }
            buttons.push(btn);
        }

        if (opt.closeBtn) {
            buttons.push(
                {
                    text: opt.closeBtnText,
                    iconCls: 'icon-no',
                    handler: function () {
                        $dg.dialog("close");
                    }
                }
            );
        }

        if (buttons.length > 0) {
            dg_opt.buttons = buttons;
        }

        dg_opt = $.yqPopPosition(dg_opt, opt);
        $dg.dialog(dg_opt);
    },

    //函数
    yqDialog_fun: function (action, params) {
        switch (action) {
            case "dialog":
                var iframeid = "iframe_" + $.urlRequest("iframenum");
                var $iframe = window.parent.$("#" + iframeid);
                return $iframe.data("$dg");
            case "options":
                if ($(this).length == 0) {
                    var $dg = $.yqDialog_fun("dialog");
                    if ($dg === undefined) {
                        return undefined;
                    } else {
                        return $dg.dialog("options");
                    }
                } else {
                    if (window.top == window.self) {
                        return $(this).dialog("options");
                    }
                    else {
                        return window.top.$(this).dialog("options");
                    }
                }
            case "close":
                if (typeof this === 'function') {
                    var $dg = $.yqDialog_fun("dialog");
                    if (!($dg === undefined)) {
                        $dg.dialog("close");
                    }
                } else {
                    if (window.top == window.self) {
                        $(this).dialog("close");
                    }
                    else {
                        window.top.$(this).dialog("close");
                    }
                }
            default:
            //默认代码块
        }
    },

    //弹出模态编辑窗体，在新的url中进行编辑
    yqWinPopEdit: function (opts, param) {
        if (typeof opts == 'string') {
            if (opts == "iframe") {
                var iframeid = "iframe_" + $.urlRequest("iframenum");
                return window.parent.$("#" + iframeid);
            } else if (opts == "options") {
                var iframeid = "iframe_" + $.urlRequest("iframenum");
                var p_params = window.parent.$("#" + iframeid).data("prevent_e");
                if (param === undefined) {
                    return p_params;
                } else {
                    if (p_params.titles === undefined) {
                        var _opt = {
                            dbname: param._tb.dbname,                //数据库
                            tbname: param._tb.tbname,                //表
                            tempno: param._tb.editModeNo,
                        };

                        if (typeof param._tb._appno != undefined) {
                            _opt.ctrlid = param._tb._ctrlid;
                            _opt.appno = param._tb._appno;
                            _opt.menuno = param._tb._menuno;
                        }

                        $.yqFormParams(_opt, function (res) {
                            console.log("yqFormParams");
                            console.log(JSON.stringify(res, null, 4));

                            if (res.error == 0) {
                                param.callback({
                                    error: 0,
                                    type: p_params.type === undefined ? "wf" : p_params.type,  //工作流模式
                                    titles: res.titles,
                                    model: res.model,
                                    row: p_params.row,
                                    action: p_params.action
                                });
                            } else {
                                $.yqMessager("提示", res.info + "[" + res.error + "]");

                                param.callback(res);
                            }
                        });
                    } else {
                        param.callback({
                            error: 0,
                            type: "base", //基础模式 无工作流
                            titles: p_params.titles,
                            model: p_params.model,
                            row: p_params.row,
                            action: p_params.action
                        });
                    }
                }
            } else if (opts == "save") {
                var p_params = window.parent.$("#" + iframeid).data("prevent_e");

                var row = param.row;
                var iframeid = "iframe_" + $.urlRequest("iframenum");
                var p_params = window.parent.$("#" + iframeid).data("prevent_e");

                if (p_params.titles === undefined) {
                    row_ = $.yqFmToData(row, param.titles, (param.fk_rows === undefined ? [] : param.fk_rows), true);
                    var _opt = {
                        dbname: param._tb.dbname,
                        tbname: param._tb.tbname,
                        rows: [{
                            "action": row_["sid"] === undefined ? "add" : "upp",
                            "row": row_
                        }],
                    };
                    if (!(param._tb._ctrlid === undefined)) {
                        _opt.ctrlid = param._tb._ctrlid;
                        _opt.appno = param._tb._appno;
                        _opt.menuno = param._tb._menuno;
                    }

                    $.yqDbAction(_opt, function (res) {
                        //console.log("save", res);
                        if (res.error == 0) {
                            if (res.rows[0].error == 0) {
                                var _row = $.extend({}, row);
                                if (res.rows[0].action == "add") {
                                    _row["sid"] = res.rows[0].sid;
                                }

                                $.yqMessager("提示", "保持成功。");

                                param.callback(true, _row);
                            } else {
                                $.yqMessager("提示", res.rows[0].info + "[" + res.rows[0].error + "]");

                                param.callback(false, res.rows[0]);
                            }
                        } else {
                            $.yqMessager("提示", res.info + "[" + res.error + "]");

                            param.callback(false, res);
                        }
                    });
                } else {
                    var yqtype = p_params.p_target.data("yqtype");
                    var opt;
                    if (yqtype == "yqDataGrid") {
                        var opt = p_params.p_target.yqDataGrid("options");
                    } else if (yqtype == "yqComboGrid") {
                        var opt = p_params.p_target.yqComboGrid("options");
                    } else if (yqtype == "yqTree") {
                        var opt = p_params.p_target.yqTree("options");
                    }

                    var oldAfterDataAction = opt.afterDataAction;
                    opt.afterDataAction = function (rows, res) {    //修改之后
                        opt.afterDataAction = oldAfterDataAction;
                        if (res.error == 0) {
                            if (res.rows[0].error == 0) {
                                //console.log(rows);
                                if (p_params.action == "add") {
                                    p_params.action = "upp";
                                } else if (p_params.action == "del") {
                                    p_params.action = "add";
                                }

                                if (param.callback) {
                                    param.callback(true, rows[0]);
                                    return;
                                }
                            }
                        }

                        if (param.callback) {
                            param.callback(false, res);
                            return;
                        }
                    }

                    if (yqtype == "yqDataGrid") {
                        if (p_params.action == "add") {
                            p_params.p_target.yqDataGrid("addRow", row);
                        } else if (p_params.action == "upp") {
                            p_params.p_target.yqDataGrid("uppRow", row);
                        } else if (p_params.action == "del") {
                            p_params.p_target.yqDataGrid("delRow", row);
                        }
                    } else if (yqtype == "yqComboGrid") {
                        if (p_params.action == "add") {
                            p_params.p_target.yqComboGrid("addRow", row);
                        } else if (p_params.action == "upp") {
                            p_params.p_target.yqComboGrid("uppRow", row);
                        } else if (p_params.action == "del") {
                            p_params.p_target.yqComboGrid("delRow", row);
                        }
                    } else if (yqtype == "yqTree") {
                        if (p_params.action == "add") {
                            p_params.p_target.yqTree("addRow", row);
                        } else if (p_params.action == "upp") {
                            p_params.p_target.yqTree("uppRow", row);
                        } else if (p_params.action == "del") {
                            p_params.p_target.yqTree("delRow", row);
                        }
                    }
                };


            } else if (opts == "get") {  //获取数据库数据
                var row = param.row;
                var iframeid = "iframe_" + $.urlRequest("iframenum");
                var p_params = window.parent.$("#" + iframeid).data("prevent_e");

                var opt;
                if (p_params.titles === undefined) {
                    opt = param._tb;
                } else {
                    var yqtype = p_params.p_target.data("yqtype");
                    if (yqtype == "yqDataGrid") {
                        var opt = p_params.p_target.yqDataGrid("options");
                    } else if (yqtype == "yqComboGrid") {
                        var opt = p_params.p_target.yqComboGrid("options");
                    } else if (yqtype == "yqTree") {
                        var opt = p_params.p_target.yqTree("options");
                    }
                }

                var _opt = {
                    action: "row",
                    dbname: opt.dbname,
                    tbname: opt.tbname,
                    keyid: opt.keyId,
                    keyval: row[opt.keyId]
                };
                if (!(p_params.titles === undefined)) {
                    _opt.ajaxUrl = opt.ajaxUrl;
                }
                if (!(opt._ctrlid === undefined)) {
                    _opt.ctrlid = opt._ctrlid;
                }
                if (!(opt._appno === undefined)) {
                    _opt.appno = opt._appno;
                }
                if (!(opt._menuno === undefined)) {
                    _opt.menuno = opt._menuno;
                }

                $.yqDbTbRow(_opt, function (res) {
                    if (res.error == 0) {
                        param.callback(true, res.row);
                    } else {
                        param.callback(false, res);
                        $.yqMessager("提示", res.info + "[" + res.error + "]");
                    }
                });
            } else if (opts == "get_prow") {  //获取父项对象选择的数据
                var iframeid = "iframe_" + $.urlRequest("iframenum");
                var p_params = window.parent.$("#" + iframeid).data("prevent_e");
                var yqtype = p_params.p_target.data("yqtype");

                var row = null;
                if (yqtype == "yqDataGrid") {
                    row = p_params.p_target.yqDataGrid("getSelected");
                } else if (yqtype == "yqComboGrid") {
                    row = p_params.p_target.yqComboGrid("getSelected");
                } else if (yqtype == "yqTree") {
                    row = p_params.p_target.yqTree("getSelected");
                }

                if (row === null) {
                    return null;
                } else {
                    return $.extend({}, row);
                }
            }
            else if (opts == "refresh") {
                var action = param.action === undefined ? "upp" : param.action;
                var row = param.row;
                var iframeid = "iframe_" + $.urlRequest("iframenum");
                var p_params = window.parent.$("#" + iframeid).data("prevent_e");
                var yqtype = p_params.p_target.data("yqtype");

                if (yqtype == "yqDataGrid") {
                    if (action == "add") {
                        p_params.p_target.yqDataGrid("appendRow", row);
                    } else if (action == "upp") {
                        p_params.p_target.yqDataGrid("updateRow", row);
                    } else if (action == "del") {
                        p_params.p_target.yqDataGrid("deleteRow", row);
                    }
                } else if (yqtype == "yqComboGrid") {
                    if (action == "add") {
                        p_params.p_target.yqComboGrid("appendRow", row);
                    } else if (action == "upp") {
                        p_params.p_target.yqComboGrid("updateRow", row);
                    } else if (action == "del") {
                        p_params.p_target.yqComboGrid("deleteRow", row);
                    }
                } else if (yqtype == "yqTree") {
                    if (action == "add") {
                        p_params.p_target.yqTree("appendRow", row);
                    } else if (action == "upp") {
                        p_params.p_target.yqTree("updateRow", row);
                    } else if (action == "del") {
                        p_params.p_target.yqTree("deleteRow", row);
                    }
                }
            } else if (opts == "close") {
                var iframeid = "iframe_" + $.urlRequest("iframenum");
                window.parent.$("#" + iframeid).data("prevent_e").win.dialog("close");
            }

            return;
        }

        var opt = $.extend({
            prevent_e: {      //调用组件信息
                clientX: 0,
                clientY: 0
            },
            mdiinfo: {            //mdi窗体信息
                clientX: 0,
                clientY: 0
            },
            title: "Dialog",
            width: 600,
            height: 400,
            maximiz: false,
            horizontalAlign: "none",    //left,right,center,none
            verticalAlign: "none",      //top,bottom,center,none
            url: "",
            onOpen: function () {

            },
            onBeforeClose: function () {
                return true;
            },
        }, opts);

        if (opt.maximiz) {
            opt.width = window.innerWidth;
            opt.height = window.innerHeight;
        }

        var $dg = $('<div></div>');
        $("body").append($dg);

        var dg_opt = {
            title: opt.title,
            width: opt.width,
            height: opt.height,
            closed: false,
            cache: false,
            maximizable: (!opt.maximiz),
            closable: true,
            resizable: (!opt.maximiz),
            doSize: (!opt.maximiz),
            modal: true,
            onOpen: function () {
                $body = $(this).dialog("body");
                $body.css("overflow", "hidden");
                $body.empty();
                var keyid = $.getKeyAdd()
                var i_url = opt.url + (opt.url.lastIndexOf("?") > 0 ? "&" : "?") + "iframenum=" + keyid;
                console.log(i_url, opt.prevent_e);

                var iframe = $('<iframe id="iframe_' + keyid + '" style="width:100%;height:100%;" src="' + i_url + '"></iframe>');
                opt.prevent_e.win = $dg;
                iframe.data("prevent_e", opt.prevent_e)
                $body.append(iframe);
                opt.onOpen.call(this);
            },
            onBeforeClose: function () {
                return opt.onBeforeClose();
            },
            onClose: function () {
                try {
                    $(this).dialog("destroy");
                    $(this).remove();
                } catch (error) {
                    console.log(error);
                }
            },

        };

        if (typeof opt.iconCls == "string") {
            dg_opt.iconCls = opt.iconCls;
        }

        dg_opt = $.yqPopPosition(dg_opt, opt);
        $dg.dialog(dg_opt);
    },

    //位置处理
    yqPopPosition: function (dg_opt, opt) {
        if (opt.height_add === undefined) {
            opt.height_add = 0;
        }

        dg_opt.resizable = true;

        var _w = $(window).width();
        var _h = $(window).height();

        if (dg_opt.width > _w) {
            dg_opt.width = _w;
        }
        if (dg_opt.height + opt.height_add > _h) {
            dg_opt.height = _h - opt.height_add;
        }

        dg_opt.left = 0;
        if (opt.horizontalAlign == "left") {
            dg_opt.left = 0;
        } else if (opt.horizontalAlign == "right") {
            dg_opt.left = _w - dg_opt.width;
        } else if (opt.horizontalAlign == "center") {
            dg_opt.left = _w / 2 - dg_opt.width / 2;
        } else {
            dg_opt.left = opt.prevent_e.clientX + opt.mdiinfo.clientX;

            if (dg_opt.left < 0) {
                dg_opt.left = 0;
            }

            if ((dg_opt.left + dg_opt.width) > _w) {
                dg_opt.left = _w - dg_opt.width;
                if (dg_opt.left < 0) {
                    delete dg_opt.left;
                }
            }
        }

        dg_opt.top = 0;
        if (opt.verticalAlign == "top") {
            dg_opt.top = 0;
        } else if (opt.verticalAlign == "bottom") {
            dg_opt.top = _h - dg_opt.height;
        } else if (opt.verticalAlign == "center") {
            dg_opt.top = _h / 2 - dg_opt.height / 2;
        } else {
            dg_opt.top = opt.prevent_e.clientY + opt.mdiinfo.clientY;

            if (dg_opt.top < 0) {
                dg_opt.top = 0;
            }

            if ((dg_opt.top + dg_opt.height + opt.height_add) > _h) {
                dg_opt.top = _h - dg_opt.height - opt.height_add;
                if (dg_opt.top < 0) {
                    delete dg_opt.top;
                }
            }
        }
        return dg_opt;
    },

    //消息提醒
    yqMessager: function (title, msg, timeout) {
        if (timeout === undefined) {
            timeout = 3000;
        }
        if (window.self == window.top) {
            $.messager.show({
                title: title,
                msg: msg,
                timeout: timeout,
                showType: 'show'
            });
        }
        else {
            window.top.$.messager.show({
                title: title,
                msg: msg,
                timeout: timeout,
                showType: 'show'
            });
        }
    },
    //确认对话框
    yqConfirm: function (title, msg, callback) {
        if (window.self == window.top) {
            $.messager.confirm({
                title: title,
                msg: msg,
                fn: function (r) {
                    callback(r);
                }
            });
        }
        else {
            window.top.$.messager.confirm({
                title: title,
                msg: msg,
                fn: function (r) {
                    callback(r);
                }
            });
        }
    },
    /*
    显示警告窗口。参数：
    title：在头部面板显示的标题文本。
    msg：显示的消息文本。
    icon：显示的图标图像。可用值有：error,question,info,warning。
    callback: 在窗口关闭的时候触发该回调函数。
    */
    yqAlert: function (title, msg, icon, callback) {
        if (icon === undefined) {
            icon = "info";
        }
        if (callback === undefined) {
            callback = function () { };
        }
        if (window.self == window.top) {
            $.messager.alert({
                title: title,
                msg: msg,
                icon: icon,
                fn: callback
            });
        }
        else {
            window.top.$.messager.alert({
                title: title,
                msg: msg,
                icon: icon,
                fn: callback
            });
        }
    },
});

//组件弹框
jQuery.extend({
    //代码编辑器
    yqCodePopEdit: function (opts) {
        var opt = $.extend({
            prevent_e: {         //调用组件信息
                id: "",
                options: {},  //调用组件jquery对象
                clientX: 0,
                clientY: 0
            },
            mdiinfo: {            //mdi窗体信息
                clientX: 0,
                clientY: 0
            },

            width: 600,
            height: 420,
            horizontalAlign: "none",    //left,right,center,none
            verticalAlign: "none",      //top,bottom,center,none
            types: ["base", "html", "javascript", "css", "json", "sql"],
            type: null,
            value: null,
            isEdit: true,
            goDocEnd: true,  //加载后，显示在尾部
            fontSize: 14,

            //markdown模式------------------
            storageType: 3,//1-数据库存储，2-外部存储
            storageName: null,
            accept: "image/*",
            chunk: false,       //分片上传
            directup: false,   //直接上传（选择文件后立即上传）
            data: { files: [], code: "" },
            //markdown模式---------------------

            callbackType: 1,   //返回value，2返回data
            callback: function (row) {

            }
        }, opts);

        if (opt.prevent_e.options === undefined) {
            opt.prevent_e.options = {};
        }

        var $body;
        var $richbox;
        var $dg = $("<div></div>");

        $("body").append($dg);

        var haveTitle = !(opt.title === undefined || opt.title === null || opt.title === "");

        var dg_opt = {
            title: opt.title,
            noheader: true,
            width: opt.width,
            height: opt.height,
            closed: false,
            cache: false,
            onOpen: function () {
                $body = $(this).dialog("body");
                $body.css({ "border-width": 0, "overflow": "hidden" });
                var $div = $('<textarea style="width:100%;height:100%;"></textarea>');
                $div.attr("id", $.getUniqueID());
                $body.append($div);

                if (haveTitle) {
                    $div.css({ height: opt.height - (opt.isEdit ? 55 : 0) - 26, width: opt.width - 13 });
                } else {
                    $div.css({ height: opt.height - (opt.isEdit ? 55 : 0), width: opt.width - 13 });
                }

                opt.edit = $div.yqCodeEdit({
                    types: opt.types,
                    type: opt.type,
                    value: opt.value,
                    isEdit: opt.isEdit,
                    goDocEnd: opt.goDocEnd,  //加载后，显示在尾部
                    fontSize: opt.fontSize,
                    //markdown模式------------------
                    storageType: opt.storageType,//1-数据库存储，2-外部存储
                    storageName: opt.storageName,
                    accept: opt.accept,
                    chunk: opt.chunk,       //分片上传
                    directup: opt.directup,   //直接上传（选择文件后立即上传）
                    data: opt.data,
                    //markdown模式------------------
                });
            },
            onResize: function (width, height) {
                if (dg_opt.buttons.length == 0) {
                    var $footer = $(this).dialog("panel").find(".dialog-button");
                    if ($footer.length > 0) {
                        $footer.css("display", "none");
                        $(this).dialog("panel").next().css("height", (height - 11) + "px");
                    }
                }

                if (haveTitle) {
                    height = opt.height - 28;
                }
                opt.edit.yqCodeEdit("resize", {
                    width: width - 13,
                    height: height - (opt.isEdit ? 55 : 23),
                });
            },
            onClose: function () {
                opt.edit.yqCodeEdit("destroy");
                $(this).dialog("destroy");
                $(this).remove();
            },
            modal: true,
        };

        dg_opt.buttons = [];
        if (opt.isEdit) {
            dg_opt.buttons.push({
                text: $.fn.yqUiExtText.btnOk,
                iconCls: 'icon-ok',
                handler: function () {
                    var value = {};
                    if (opt.callbackType == 1) {
                        value = {
                            type: opt.edit.yqCodeEdit("getType"),
                            value: opt.edit.yqCodeEdit("getValue")
                        };
                    } else {
                        value = opt.edit.yqCodeEdit("getData");
                    }

                    if (opt.prevent_e.options.beforeChange) {
                        opt.prevent_e.options.beforeChange.call($body, value,
                            function (tf, value2) {
                                if (!tf) {
                                    return;
                                }

                                if (opt.callback) {
                                    opt.callback(value2);
                                }
                                $dg.dialog("close");
                            });
                    }
                    else {
                        if (opt.callback) {
                            opt.callback(value);
                        }

                        $dg.dialog("close");
                    }
                }
            });

            if (!haveTitle) {
                dg_opt.buttons.push({
                    text: $.fn.yqUiExtText.btnNo,
                    iconCls: 'icon-no',
                    handler: function () {
                        $dg.dialog("close");
                    }
                });
            }
        } else if (!haveTitle) {
            dg_opt.buttons.push({
                text: $.fn.yqUiExtText.btnClose,
                iconCls: 'icon-cancel',
                handler: function () {
                    $dg.dialog("close");
                }
            });
        }

        //添加标题
        if (haveTitle) {
            dg_opt.noheader = false;
            dg_opt.title = opt.title;
        }

        dg_opt = $.yqPopPosition(dg_opt, opt);

        $dg.dialog(dg_opt);
    },

    // html模型编辑器
    yqTmplHtmlPopEdit: function (opts) {
        var opt = $.extend({
            width: 800,
            height: 600,
            horizontalAlign: "none",    //left,right,center,none
            verticalAlign: "none",      //top,bottom,center,none
            value: null,
            isEdit: true,
            titles: [],
            prevent_e: {         //调用组件信息
                id: '',
                options: {},  //调用组件jquery对象
                clientX: 0,
                clientY: 0
            },
            mdiinfo: {            //mdi窗体信息
                clientX: 0,
                clientY: 0
            },
            callback: function (text) {

            }
        }, opts);

        var $body;
        var $htmlbox;
        var $dg = $('<div></div>');
        $('body').append($dg);
        var dg_opt = {
            title: opt.title,
            noheader: true,
            width: opt.width,
            height: opt.height,
            closed: false,
            cache: false,
            onOpen: function () {
                $body = $(this).dialog('body');
                $body.css({ "border-width": 0, "overflow": "hidden" });
                $body.attr('id', $.getUniqueID());
                $htmlbox = $('<div></div>');
                $body.append($htmlbox);// 必须先append出来，才能访问iframe内部的内容
                $htmlbox.yqTmplHtmlEdit({
                    border: false,
                    isEdit: opt.isEdit,

                    width: $body.width(),
                    height: $body.height() - 55,
                    titles: opt.titles,
                    value: opt.value
                });
            },
            onResize: function (width, height) {
                $htmlbox.yqTmplHtmlEdit("resize", {
                    width: width - 12,
                    height: height - 55,
                });
            },
            onClose: function () {
                $htmlbox = $(this).dialog('body').children('div');
                $htmlbox.yqTmplHtmlEdit('destroy');
                $(this).dialog('destroy');
                $(this).remove();
            },
            modal: true,
        };
        if (opt.isEdit) {
            dg_opt.buttons = [{
                text: $.fn.yqUiExtText.btnOk,
                iconCls: 'icon-ok',
                handler: function () {
                    var value = $htmlbox.yqTmplHtmlEdit('getValue');
                    if (opt.prevent_e.options.beforeChange) {
                        opt.prevent_e.options.beforeChange.call($body, value,
                            function (tf, value2) {
                                if (!tf) {
                                    return;
                                }
                                if (opt.callback) {
                                    opt.callback(value2);
                                }
                                $dg.dialog('close');
                            })
                    } else {
                        if (opt.callback) {
                            opt.callback(value);
                        }
                        $dg.dialog('close');
                    }
                }
            }, {
                text: $.fn.yqUiExtText.btnNo,
                iconCls: 'icon-no',
                handler: function () {
                    $dg.dialog('close');
                }
            }];
        } else {
            dg_opt.buttons = [{
                text: $.fn.yqUiExtText.btnClose,
                iconCls: 'icon-cancel',
                handler: function () {
                    $dg.dialog('close');
                }
            }];
        }
        dg_opt = $.yqPopPosition(dg_opt, opt);
        $dg.dialog(dg_opt);
    },

    //ui_type=13  NCheckbox
    yqNCheckboxPopEdit: function (opts) {
        var opt = $.extend({
            prevent_e: {         //调用组件信息
                id: "",
                options: {},  //调用组件jquery对象
                clientX: 0,
                clientY: 0
            },
            mdiinfo: {            //mdi窗体信息
                clientX: 0,
                clientY: 0
            },
            width: 600,
            height: 420,
            horizontalAlign: "none",    //left,right,center,none
            verticalAlign: "none",      //top,bottom,center,none
            lists: [],
            default: "",
            value: null,
            isEdit: true,

            callback: function (row) {

            }
        }, opts);

        var $body;
        var $dg = $("<div></div>");

        $("body").append($dg);

        var dg_opt = {
            title: opt.title,
            noheader: true,
            width: opt.width,
            height: opt.height,
            closed: false,
            cache: false,
            onOpen: function () {
                $body = $(this).dialog("body");
                var $form = $('<form></form>');
                $body.append($form);
                var $div = $('<div style="width:100%;height:100%;"></div>');
                $div.attr("id", $.getUniqueID());
                $form.append($div);
                $div.css({ padding: "3px 8px" });

                opt.edit = $div;

                var len_ = 5;
                var data = [];
                var v_ = [];
                for (let i = 0; i < opt.lists.length; i++) {
                    data.push({
                        value: opt.lists[i].no,
                        label: opt.lists[i].name
                    });

                    var l_ = $.yqGetStrLen(opt.lists[i].name);
                    if (len_ < l_) {
                        len_ = l_;
                    }
                }
                if (typeof opt.value == "object") {
                    v_ = opt.value;
                }
                else if (!(opt.value === null || opt.value == "")) {
                    var sp_ = opt.value.split(",");
                    for (let i = 0; i < sp_.length; i++) {
                        v_.push(parseInt(sp_[i]));
                    }
                }

                $div.checkgroup({
                    name: "no",
                    value: v_,
                    data: data,
                    labelWidth: len_ * 7
                });

                if (!opt.isEdit) {
                    $div.find(".checkbox-f").checkbox("disable");
                }
            },
            onClose: function () {
                //opt.edit.find(".checkbox-f").checkbox("destroy");
                $(this).dialog("destroy");
                $(this).remove();
            },
            modal: true,
        };

        if (opt.isEdit) {
            dg_opt.buttons = [{
                text: $.fn.yqUiExtText.btnOk,
                iconCls: 'icon-ok',
                handler: function () {
                    var value = opt.edit.checkgroup("getValue");
                    if (opt.prevent_e.options.beforeChange) {
                        opt.prevent_e.options.beforeChange.call($body, value,
                            function (tf, value2) {
                                if (!tf) {
                                    return;
                                }

                                if (opt.callback) {
                                    var v_ = "";
                                    for (let i = 0; i < value2.length; i++) {
                                        v_ += (v_ == "" ? "" : ",") + value2[i];

                                    }
                                    opt.callback(v_);
                                }

                                $dg.dialog("close");
                            })
                    }
                    else {
                        if (opt.callback) {
                            var v_ = "";
                            for (let i = 0; i < value.length; i++) {
                                v_ += (v_ == "" ? "" : ",") + value[i];

                            }
                            opt.callback(v_);
                        }

                        $dg.dialog("close");
                    }
                }
            }, {
                text: $.fn.yqUiExtText.btnNo,
                iconCls: 'icon-no',
                handler: function () {
                    $dg.dialog("close");
                }
            }];
        }
        else {
            dg_opt.buttons = [{
                text: $.fn.yqUiExtText.btnClose,
                iconCls: 'icon-cancel',
                handler: function () {
                    $dg.dialog("close");
                }
            }];
        }

        dg_opt = $.yqPopPosition(dg_opt, opt);

        $dg.dialog(dg_opt);
    },

    //TbEdit 表格数据弹窗编辑框 属性数据 ui_type=15
    yqTableEditPopEdit: function (opts) {
        var opt = $.extend({
            ajaxUrl: "/_db.html",
            title: "测试",
            width: 600,
            height: 420,
            horizontalAlign: "none",    //left,right,center,none
            verticalAlign: "none",      //top,bottom,center,none
            titles: [],
            rows: [],
            isEdit: true,
            isAdd: true,
            isDel: true,
            isMove: true,
            toexcel: false, //Excel导出
            excelName: "excel导出",   //Excel导出文件名
            inexcel: false, //Excel导入   
            sumList: [],        //合计字段：a,b,c
            frozenNum: 0, //锁定列数量（锁定左侧）
            rownumbers: true,
            showHeader: true, //显示表头
            prevent_e: {         //调用组件信息
                id: "",
                options: {},  //调用组件jquery对象
                clientX: 0,
                clientY: 0
            },
            mdiinfo: {            //mdi窗体信息
                clientX: 0,
                clientY: 0
            },
        }, opts);

        var $body;
        var $dg = $("<div></div>");

        $("body").append($dg);

        var dg_opt = {
            title: opt.title,
            noheader: true,
            width: opt.width,
            height: opt.height,
            closed: false,
            cache: false,
            onOpen: function () {
                $body = $(this).dialog("body");
                $body.css({ "border-width": 0, "overflow": "hidden" });
                opt.$div = $("<div></div>");
                $body.append(opt.$div);
                opt.$div.attr("id", $.getUniqueID());

                var _opt = {
                    ajaxUrl: opt.ajaxUrl,
                    editModeW: opt.width - 12,
                    editModeH: opt.height - 55,
                    titles: opt.titles,  //数据列配置对象
                    rows: opt.rows,
                    isEdit: opt.isEdit,
                    isAdd: opt.isAdd,
                    isDel: opt.isDel,
                    isMove: opt.isMove,
                    toexcel: opt.toexcel,
                    excelName: opt.excelName,
                    inexcel: opt.inexcel,
                    sumList: opt.sumList,        //合计字段：a,b,c
                    frozenNum: opt.frozenNum, //锁定列数量（锁定左侧）
                    rownumbers: opt.rownumbers,
                    showHeader: opt.showHeader
                }
                if (!(opt.dbname === undefined ||
                    opt.dbname === null ||
                    opt.dbname == "")) {
                    _opts.dbname = opt.dbname;
                }

                if (typeof opt.prevent_e.options.beforeBindingTitle == "function") {
                    _opt.beforeBindingTitle = opt.prevent_e.options.beforeBindingTitle;
                }
                if (typeof opt.prevent_e.options.afterBindingTitle == "function") {
                    _opt.afterBindingTitle = opt.prevent_e.options.afterBindingTitle;
                }
                if (typeof opt.prevent_e.options.onClickRow == "function") {
                    _opt.onClickRow = opt.prevent_e.options.onClickRow;
                }
                if (typeof opt.prevent_e.options.endEditing == "function") {
                    _opt.endEditing = opt.prevent_e.options.endEditing;
                }
                if (typeof opt.prevent_e.options.beforeAdd == "function") {
                    _opt.beforeAdd = opt.prevent_e.options.beforeAdd;
                }

                opt.$div.yqTableEdit(_opt);
            },
            onResize: function (width, height) {
                opt.$div.yqTableEdit("resize", {
                    width: width - 12,
                    height: height - 55,
                });
            },
            onClose: function () {
                opt.$div.yqTableEdit("destroy");
                $(this).dialog("destroy");
                $(this).remove();
            },
            modal: true,

        };

        if (opt.isEdit) {
            dg_opt.buttons = [{
                text: $.fn.yqUiExtText.btnOk,
                iconCls: 'icon-ok',
                handler: function () {
                    var rows = opt.$div.yqTableEdit("getRows");

                    if (opt.prevent_e.options.beforeChange) {
                        opt.prevent_e.options.beforeChange.call(opt.$div, rows,
                            function (tf, rows2) {
                                if (!tf) {
                                    return;
                                }

                                if (opt.callback) {
                                    opt.callback(rows2);
                                }
                                $dg.dialog("close");
                            })
                    }
                    else {
                        if (opt.callback) {
                            opt.callback(rows);
                        }

                        $dg.dialog("close");
                    }
                }
            }, {
                text: $.fn.yqUiExtText.btnNo,
                iconCls: 'icon-no',
                handler: function () {
                    $dg.dialog("close");
                }
            }];
        }
        else {
            dg_opt.buttons = [{
                text: $.fn.yqUiExtText.btnClose,
                iconCls: 'icon-cancel',
                handler: function () {
                    $dg.dialog("close");
                }
            }];
        }

        dg_opt = $.yqPopPosition(dg_opt, opt);

        $dg.dialog(dg_opt);
    },

    //TreeEdit 树形弹出框 ui_type=16
    yqTreeEditPopEdit: function (opts) {
        var opt = $.extend({
            ajaxUrl: "/_db.html",
            title: "测试",
            width: 600,
            height: 420,
            horizontalAlign: "none",    //left,right,center,none
            verticalAlign: "none",      //top,bottom,center,none
            titles: [],
            data: [],
            displayMember: "",
            isEdit: true,
            isAdd: true,
            isDel: true,
            prevent_e: {         //调用组件信息
                id: "",
                options: {},  //调用组件jquery对象
                clientX: 0,
                clientY: 0
            },
            mdiinfo: {            //mdi窗体信息
                clientX: 0,
                clientY: 0
            },
        }, opts);

        var $body;
        var $dg = $("<div></div>");

        $("body").append($dg);

        opt.onload = false;
        var dg_opt = {
            title: opt.title,
            noheader: true,
            width: opt.width,
            height: opt.height,
            closed: false,
            cache: false,
            onOpen: function () {
                $body = $(this).dialog("body");
                $body.css({ "border-width": 0, "overflow": "hidden" });
                opt.$div = $("<div></div>");
                $body.append(opt.$div);
                opt.$div.attr("id", $.getUniqueID());

                var _opt = {
                    ajaxUrl: opt.ajaxUrl,
                    displayMember: opt.displayMember,          //显示字段
                    titles: opt.titles,  //数据列配置对象
                    data: opt.data,
                    editModeW: (opt.width - 12),  //模态编辑器宽度 格式为 800（数字）
                    editModeH: (opt.height - 55), //模态编辑器高度 格式为 600（数字）
                    isEdit: opt.isEdit,
                    isAdd: opt.isAdd,
                    isDel: opt.isDel,
                };
                if (!(opt.dbname === undefined ||
                    opt.dbname === null ||
                    opt.dbname == "")) {
                    _opts.dbname = opt.dbname;
                }

                if (typeof opt.prevent_e.options.beforeBindingTitle == "function") {
                    _opt.beforeBindingTitle = opt.prevent_e.options.beforeBindingTitle;
                }
                if (typeof opt.prevent_e.options.afterBindingTitle == "function") {
                    _opt.afterBindingTitle = function () {
                        opt.onload = true;
                        opt.prevent_e.options.afterBindingTitle.call(this);
                    }
                }
                if (typeof opt.prevent_e.options.beforeAdd == "function") {
                    _opt.beforeAdd = opt.prevent_e.options.beforeAdd;
                }
                if (typeof opt.prevent_e.options.endEditing == "function") {
                    _opt.endEditing = opt.prevent_e.options.endEditing;
                }
                opt.$div.yqTreeEdit(_opt);

            },
            onResize: function (width, height) {
                if (opt.onload == false) {
                    return;
                }

                opt.$div.yqTreeEdit("resize", {
                    width: width - 12,
                    height: height - 55,
                });
            },
            onClose: function () {
                opt.$div.yqTreeEdit("destroy");
                $(this).dialog("destroy");
                $(this).remove();
            },
            modal: true, buttons: [{
                text: $.fn.yqUiExtText.btnOk,
                iconCls: 'icon-ok',
                handler: function () {
                    var data = opt.$div.yqTreeEdit('getData');

                    if (opt.prevent_e.options.beforeChange) {
                        opt.prevent_e.options.beforeChange.call($body, data,
                            function (tf, data2) {
                                if (!tf) {
                                    return;
                                }

                                if (opt.callback) {
                                    opt.callback(data2);
                                }
                                $dg.dialog("close");
                            })
                    }
                    else {
                        if (opt.callback) {
                            opt.callback(data);
                        }

                        $dg.dialog("close");
                    }
                }
            }, {
                text: $.fn.yqUiExtText.btnNo,
                iconCls: 'icon-no',
                handler: function () {
                    $dg.dialog("close");
                }
            }]
        };

        dg_opt = $.yqPopPosition(dg_opt, opt);

        $dg.dialog(dg_opt);
    },

    //属性弹窗编辑框 attr 属性数据 ui_type=17
    yqAttrPopEdit: function (opts) {
        var opt = $.extend({
            prevent_e: {         //调用组件信息
                id: "",
                options: {},  //调用组件jquery对象
                clientX: 0,
                clientY: 0
            },
            mdiinfo: {            //mdi窗体信息
                clientX: 0,
                clientY: 0
            },

            ajaxUrl: "/_db.html",
            titles: [],
            action: "add",
            row: [],
            isEdit: true,
            loadDefault: false,   //加载默认值
            blankTag: "*",     //值不能为空，标题附加标记
            removeUnUse: false,

            width: 600,
            height: 420,
            horizontalAlign: "none",    //left,right,center,none
            verticalAlign: "none",      //top,bottom,center,none
            callback: function (row) {

            },
        }, opts);

        if (opt.prevent_e.options === undefined) {
            opt.prevent_e.options = {};
        }

        var $body;
        var $dg = $("<div></div>");

        $("body").append($dg);
        opt.onload = false;
        var dg_opt = {
            title: opt.title,
            noheader: true,
            width: opt.width,
            height: opt.height,
            closed: false,
            cache: false,
            onOpen: function () {
                $body = $(this).dialog("body");
                $body.css({ "border-width": 0, "overflow": "hidden" });
                $body.attr("id", "yqpop_17");

                var _opts = {
                    ajaxUrl: opt.ajaxUrl,
                    titles: opt.titles,
                    action: opt.action,
                    row: opt.row,
                    isEdit: opt.isEdit,
                    loadDefault: opt.loadDefault,
                    blankTag: opt.blankTag,
                    removeUnUse: opt.removeUnUse,
                };
                if (!(opt.dbname === undefined ||
                    opt.dbname === null ||
                    opt.dbname == "")) {
                    _opts.dbname = opt.dbname;
                }

                if (typeof opt.prevent_e.options.edit_beforeBindingTitle == "function") {
                    _opts.beforeBindingTitle = opt.prevent_e.options.edit_beforeBindingTitle;
                }
                if (typeof opt.prevent_e.options.edit_afterBindingTitle == "function") {
                    _opts.afterBindingTitle = opt.prevent_e.options.edit_afterBindingTitle;
                }
                if (typeof opt.prevent_e.options.endEditing == "function") {
                    _opts.endEditing = opt.prevent_e.options.endEditing;
                }

                $body.yqAttrEdit(_opts);

                opt.onload = true;
            },
            onResize: function (width, height) {
                if (opt.onload == false) {
                    return;
                }

                $body.yqAttrEdit("resize", {
                    width: width - 12,
                    height: height - 12,
                });
            },
            onClose: function () {
                //$body.yqAttrEdit("destroy");
                $(this).dialog("destroy");
                $(this).remove();
            },
            modal: true,

        };

        if (opt.isEdit) {
            dg_opt.buttons = [{
                text: $.fn.yqUiExtText.btnOk,
                iconCls: 'icon-ok',
                handler: function () {
                    var row = $body.yqAttrEdit("getRow");

                    if (opt.prevent_e.options.beforeChange) {
                        opt.prevent_e.options.beforeChange.call($body, row,
                            function (tf, row2) {
                                if (!tf) {
                                    return;
                                }

                                if (opt.callback) {
                                    opt.callback(row2);
                                }
                                $dg.dialog("close");
                            })
                    }
                    else {
                        if (opt.callback) {
                            opt.callback(row);
                        }

                        $dg.dialog("close");
                    }
                }
            }, {
                text: $.fn.yqUiExtText.btnNo,
                iconCls: 'icon-no',
                handler: function () {
                    $dg.dialog("close");
                }
            }];
        }
        else {
            dg_opt.buttons = [{
                text: $.fn.yqUiExtText.btnClose,
                iconCls: 'icon-cancel',
                handler: function () {
                    $dg.dialog("close");
                }
            }];
        }

        opt.height_add = 42;
        dg_opt = $.yqPopPosition(dg_opt, opt);

        $dg.dialog(dg_opt);
    },

    //form表单弹窗编辑框 attr 属性数据 ui_type=17
    yqFormPopEdit: function (opts) {
        var opt = $.extend({
            prevent_e: {         //调用组件信息
                id: "",
                options: {},  //调用组件jquery对象
                clientX: 0,
                clientY: 0
            },
            mdiinfo: {            //mdi窗体信息
                clientX: 0,
                clientY: 0
            },

            titles: [],
            model: null,
            action: "add",
            row: {},
            isEdit: true,
            loadDefault: false,   //加载默认值
            blankTag: "*",     //值不能为空，标题附加标记
            removeUnUse: false,

            ok_text: $.fn.yqUiExtText.btnOk,
            no_text: $.fn.yqUiExtText.btnNo,
            close_text: $.fn.yqUiExtText.btnClose,

            width: 600,
            height: 420,
            horizontalAlign: "none",    //left,right,center,none
            verticalAlign: "none",      //top,bottom,center,none
            callback: function (row) {

            }
        }, opts);

        if (opt.prevent_e.options === undefined) {
            opt.prevent_e.options = {};
        }

        var $body;
        var $dg = $("<div></div>");

        $("body").append($dg);

        var dg_opt = {
            title: opt.title,
            noheader: true,
            width: opt.width,
            height: opt.height,
            closed: false,
            cache: false,
            onOpen: function () {
                $body = $(this).dialog("body");
                $body.css({ "border-width": 0, padding: "8px 0 0 8px", overflow: "auto" });
                $body.attr("id", $.getUniqueID());

                var _opts = {
                    ajaxUrl: opt.ajaxUrl,
                    titles: opt.titles,
                    model: opt.model,
                    action: opt.action,
                    row: opt.row,
                    loadDefault: opt.loadDefault,
                    isEdit: opt.isEdit,
                    blankTag: "*",
                    removeUnUse: opt.removeUnUse,
                }
                if (!(opt.dbname === undefined ||
                    opt.dbname === null ||
                    opt.dbname == "")) {
                    _opts.dbname = opt.dbname;
                }

                $body.yqFormEdit(_opts);
            },
            onClose: function () {
                $body.yqFormEdit("destroy");
                $(this).dialog("destroy");
                $(this).remove();
            },
            modal: true,
        };

        if (typeof opt.iconCls == "string") {
            dg_opt.iconCls = opt.iconCls;
        }

        if (opt.isEdit) {
            dg_opt.buttons = [{
                text: opt.ok_text,
                iconCls: 'icon-ok',
                handler: function () {
                    var row = $body.yqFormEdit("getRow");

                    if (opt.prevent_e.options.beforeChange) {
                        opt.prevent_e.options.beforeChange.call($body, row,
                            function (tf, row2) {
                                if (!tf) {
                                    return;
                                }

                                if (opt.callback) {
                                    opt.callback(row2);
                                }

                                $dg.dialog("close");
                            })
                    }
                    else {
                        if (opt.callback) {
                            opt.callback(row);
                        }

                        $dg.dialog("close");
                    }
                }
            }, {
                text: opt.no_text,
                iconCls: 'icon-no',
                handler: function () {
                    $dg.dialog("close");
                }
            }];
        }
        else {
            dg_opt.buttons = [{
                text: opt.close_text,
                iconCls: 'icon-cancel',
                handler: function () {
                    $dg.dialog("close");
                }
            }];
        }

        dg_opt = $.yqPopPosition(dg_opt, opt);

        $dg.dialog(dg_opt);
    },

    // html编辑器 后面扩展兼容markdown
    yqHtmlPopEdit: function (opts) {
        var opt = $.extend({
            width: 800,
            height: 600,
            horizontalAlign: "none",    //left,right,center,none
            verticalAlign: "none",      //top,bottom,center,none

            storageType: 2,//1-数据库存储，2-外部存储
            storageName: null,
            accept: "image/*",
            chunk: false,       //分片上传
            directup: false,   //直接上传（选择文件后立即上传）
            data: { files: [], html: "" },
            isEdit: true,   //可编辑
            lang: 'zh-Hans', //语言

            prevent_e: {         //调用组件信息
                id: '',
                options: {},  //调用组件jquery对象
                clientX: 0,
                clientY: 0
            },
            mdiinfo: {            //mdi窗体信息
                clientX: 0,
                clientY: 0
            },
            callback: function (data) {

            }
        }, opts);

        var $body;
        var $htmlbox;
        var $dg = $('<div></div>');
        $('body').append($dg);
        var dg_opt = {
            title: opt.title,
            noheader: true,
            width: opt.width,
            height: opt.height,
            closed: false,
            cache: false,
            onOpen: function () {
                $body = $(this).dialog('body');
                $body.css({ "border-width": 0, "overflow": "hidden" });
                $htmlbox = $('<textarea style="width:' + (opt.width - 8) + 'px;height:' + (opt.height - 50) + 'px;"></textarea>');
                $htmlbox.attr('id', $.getUniqueID());
                $body.append($htmlbox);// 必须先append出来，才能访问iframe内部的内容

                $htmlbox.yqHtmlEdit({
                    storageType: opt.storageType,//1-数据库存储，2-外部存储
                    storageName: opt.storageName,
                    accept: opt.accept,
                    chunk: opt.chunk,       //分片上传
                    directup: opt.directup,   //直接上传（选择文件后立即上传）
                    data: opt.data,
                    isEdit: opt.isEdit,   //可编辑
                    lang: opt.lang, //语言
                });
            },
            onResize: function (width, height) {
                $htmlbox.yqHtmlEdit("resize", {
                    width: width - 12,
                    height: height - 55,
                });
            },
            onClose: function () {
                $htmlbox = $(this).dialog('body').children('textarea');
                $htmlbox.yqHtmlEdit('destroy');
                $(this).dialog('destroy');
                $(this).remove();
            },
            modal: true,
        };

        if (opt.isEdit) {
            dg_opt.buttons = [{
                text: $.fn.yqUiExtText.btnOk,
                iconCls: 'icon-ok',
                handler: function () {
                    var data = $htmlbox.yqHtmlEdit('getData');
                    if (opt.prevent_e.options.beforeChange) {
                        opt.prevent_e.options.beforeChange.call($body, data,
                            function (tf, data2) {
                                if (!tf) {
                                    return;
                                }
                                if (opt.callback) {
                                    opt.callback(data2);
                                }
                                $dg.dialog('close');
                            })
                    } else {
                        if (opt.callback) {
                            opt.callback(data);
                        }
                        $dg.dialog('close');
                    }
                }
            }, {
                text: $.fn.yqUiExtText.btnNo,
                iconCls: 'icon-no',
                handler: function () {
                    $dg.dialog('close');
                }
            }];
        } else {
            dg_opt.buttons = [{
                text: $.fn.yqUiExtText.btnClose,
                iconCls: 'icon-cancel',
                handler: function () {
                    $dg.dialog('close');
                }
            }];
        }
        dg_opt = $.yqPopPosition(dg_opt, opt);
        $dg.dialog(dg_opt);
    },

    //数据移动顺序
    yqRowsPopMove: function (options) {
        var opt = $.extend({
            ajaxUrl: "/_db.html",
            prevent_e: {         //调用组件信息
                id: "",
                options: {},  //调用组件jquery对象
                clientX: 0,
                clientY: 0
            },
            mdiinfo: {            //mdi窗体信息
                clientX: 0,
                clientY: 0
            },
            title: $.fn.yqUiExtText.DialogMoveTitle,
            width: 600,
            height: 400,
            horizontalAlign: "none",    //left,right,center,none
            verticalAlign: "none",      //top,bottom,center,none
            titles: [],
            rows: [],
            callback: function (rows) { }
        }, options);

        var $dg = $('<div></div>');
        $("body").append($dg);

        var $body;

        var dg_opt = {
            title: opt.title,
            width: opt.width,
            height: opt.height,
            closed: false,
            cache: false,
            onOpen: function () {
                $body = $(this).dialog("body");
                $body.css({ "border-width": 0, "overflow": "hidden" });
                $body.attr("id", "yqpop_move");

                var columns = $.yqDgColumns.call($body, opt.titles);

                $body.datagrid({
                    width: '100%',
                    height: opt.height - 30,
                    columns: columns,
                    rownumbers: true,
                    fitColumns: false,
                    scrollbarSize: 0,
                    singleSelect: true,
                    dragSelection: true,
                    onLoadSuccess: function () {
                        $(this).datagrid('enableDnd');
                    },
                });

                var rows = $.yqFmToViews(opt.rows, opt.titles);

                if (opt.fk_rows === undefined) {
                    //外键处理
                    var fks = $.yqFmForienKeys(rows, opt.titles);
                    //console.log("fks", fks);
                    if (fks.length > 0) {
                        $.yqDbTbForienKey({
                            ajaxUrl: opt.ajaxUrl,
                            rows: fks
                        },
                            function (res) {
                                if (res.error == 0) {
                                    $body.datagrid("options").fk_rows = res.rows;
                                    $body.datagrid("loadData", { "rows": rows });
                                }
                            });
                    }
                    else {
                        $body.datagrid("options").fk_rows = [];
                        $body.datagrid("loadData", { "rows": rows });
                    }
                }
                else {
                    $body.datagrid("options").fk_rows = opt.fk_rows;
                    $body.datagrid("loadData", { "rows": rows });
                }
            },
            onResize: function (width, height) {
                //console.log("onResize");
                $body.datagrid("resize", {
                    width: width - 12,
                    height: height - 30,
                });
            },
            onClose: function () {
                try {
                    $(this).dialog("destroy");
                    $(this).remove();
                } catch (error) {
                    console.log(error);
                }
            },
            modal: true,
            buttons: [{
                text: $.fn.yqUiExtText.btnOk,
                iconCls: 'icon-ok',
                handler: function () {
                    var b_rows = $body.datagrid("getRows");
                    if (opt.callback) {
                        opt.callback(b_rows);
                    }

                    $dg.dialog("close");
                }
            }, {
                text: $.fn.yqUiExtText.btnNo,
                iconCls: 'icon-no',
                handler: function () {
                    $dg.dialog("close");
                }
            }]
        };

        opt.height_add = 51;
        dg_opt = $.yqPopPosition(dg_opt, opt);

        $dg.dialog(dg_opt);
    },

    //数据查询选择
    yqRowsPopSelect: function (options) {
        var opt = $.extend({
            ajaxUrl: "/_db.html",

            mdiinfo: {            //mdi窗体信息
                clientX: 0,
                clientY: 0
            },
            prevent_e: {         //调用组件信息
                id: "",
                options: {},  //调用组件jquery对象
                clientX: 0,
                clientY: 0
            },

            title: $.fn.yqUiExtText.DialogSelectTitle,

            dbname: "yqbase",               //数据库
            tbname: "",                     //表
            tempno: 100,                    //实例 
            addWhere: "",                   //额外条件
            order: "",                     //排序

            width: 600,
            height: 400,
            horizontalAlign: "none",    //left,right,center,none
            verticalAlign: "none",      //top,bottom,center,none

            isPage: true,                   //分页
            pageSize: 10,
            pageNo: 1,
            pageList: [5, 10, 20, 30, 40, 50],

            seekSimple: true,     //简单查询
            seekSimpleDDLW: 150,  //条件宽度
            seekSimpleTxtW: 200,  //条件宽度

            isSeek: true,
            seekNo: -1,                      //查询模板编码  displayType=2生效
            seekModeW: 800,                  //模态编辑器宽度 格式为 800（数字）
            seekModeH: 600,                  //模态编辑器高度 格式为 600（数字）

            choiceOne: true,                // true 单选,false 多选
            valueMember: "sid",             //值字段
            displayMember: "sid",            //显示  
            defaultValue: null,

            callback: function (row) { }
        }, options);

        opt.pid = $.getUniqueID();

        if (opt.defaultValue === "" || opt.defaultValue === undefined) {
            opt.defaultValue = null;
        }

        var $dg = $('<div></div>');
        $("body").append($dg);

        var $body;

        opt.running = false;
        opt.onload = false;
        init_ui();

        function init_ui() {
            var dg_opt = {
                //title: opt.title,
                noheader: true,
                width: opt.width,
                height: opt.height,
                closed: false,
                cache: false,
                onOpen: function () {
                    $body = $(this).dialog("body");
                    $body.css({ "border-width": 0, "overflow": "hidden" });
                    $body.attr("id", opt.pid);

                    $body.data("yqtype", "datagrid");

                    if (!opt.choiceOne) {
                        opt.textbox_ = $("<div></div>");
                        $body.append(opt.textbox_);
                        opt.textbox_.css({
                            height: 30,
                            width: opt.width - 14
                        });
                    }

                    opt.dg_ = $("<div></div>");
                    $body.append(opt.dg_);
                    $body.options = opt;

                    get_columns($body, function (columns) {
                        get_seektitle($body, function (seektitle) {
                            var $toolbar = $("<div></div>");
                            $body.after($toolbar);
                            $toolbar.yqEditMenu({
                                type: 1,
                                mini: true,
                                copy: false,
                                addroot: false,
                                add: false,
                                upp: false,
                                del: false,
                                save: false,
                                isdel: false,
                                cut: false,
                                move: false,
                                links: [],  //显示的链接菜单
                                menus: [],  //显示在其它中的菜单

                                titles: seektitle,
                                isSimple: opt.seekSimple,
                                isSimpleDDLW: opt.seekSimpleDDLW,
                                isSimpleTxtW: opt.seekSimpleTxtW,

                                isSeek: opt.isSeek,
                                seekModeW: opt.seekModeW,
                                seekModeH: opt.seekModeH,

                                afterBindingTitle: function () {

                                }, //标题绑定后
                                onSeek: function (where) {           //查询
                                    console.log("where", where);
                                    loadData(where, function (rows) {
                                        if (!opt.choiceOne) {
                                            $("#" + opt.pid + "_ok").linkbutton("enable");
                                        }
                                    });
                                }
                            });

                            var data_opt = {
                                width: opt.width - 12,
                                height: (!opt.choiceOne ? (opt.height - 86) : (opt.height - 56)),
                                border: false,
                                columns: columns,
                                rownumbers: true,
                                fitColumns: false,
                                scrollbarSize: 0,
                                dragSelection: false,
                                singleSelect: true,
                                toolbar: $toolbar,
                                onLoadSuccess: function (data) {
                                    opt.onload = true;
                                }
                            };

                            if (opt.choiceOne) {
                                data_opt.onClickRow = function (index, row) {
                                    if (row == null) {
                                        $("#" + opt.pid + "_ok").linkbutton("disable");
                                    } else {
                                        $("#" + opt.pid + "_ok").linkbutton("enable");
                                    }
                                };
                                data_opt.onDblClickRow = function (index, row) {
                                    if (opt.callback) {
                                        opt.callback(row);
                                    }
                                    $dg.dialog("close");
                                };
                            } else {
                                data_opt.onDblClickRow = function (index, row) {
                                    var has_ = false;
                                    for (let i = 0; i < opt.choice_rows.length; i++) {
                                        const item = opt.choice_rows[i];
                                        if (item[opt.valueMember] == row[opt.valueMember]) {
                                            has_ = true;
                                            break;
                                        }
                                    }
                                    if (!has_) {
                                        init_textboxadd(row);
                                    }
                                };
                            }

                            if (opt.isPage) {
                                data_opt.pagination = true;  //显示分页
                                data_opt.pageNumber = opt.pageNo;
                                data_opt.pageSize = opt.pageSize;
                                data_opt.pageList = opt.pageList;
                            }

                            opt.dg_.datagrid(data_opt);

                            opt.dg_.datagrid("options").onLoadSuccess = function (data) {
                                opt.running = false;
                                opt.onload = true;
                                opt.dg_.datagrid("loaded");

                                if (!(opt.defaultValue === null)) {
                                    var rows = $(this).datagrid("getRows");
                                    for (var i = 0; i < rows.length; i++) {
                                        if (rows[i][opt.valueMember] == opt.defaultValue) {
                                            $(this).datagrid("selectRow", i);
                                            break;
                                        }
                                    }
                                }

                                if (opt.isPage) {
                                    var pager = $(this).datagrid('getPager');
                                    pager.pagination('refresh', {
                                        total: data.recordCount,    //;
                                        pageNumber: data.pageNo
                                    });
                                }
                            };

                            if (opt.isPage) {
                                var $pager = opt.dg_.datagrid('getPager');
                                $pager.pagination({
                                    onSelectPage: function (pageNo, pageSize) {
                                        opt.pageSize = pageSize;
                                        opt.pageNo = pageNo;
                                        //console.log(pageNo, pageSize);
                                        loadData(opt.prewhere, function (rows) {
                                            if (!opt.choiceOne) {
                                                $("#" + opt.pid + "_ok").linkbutton("enable");
                                            }
                                        });
                                    }
                                });
                            }

                            if (opt.defaultValue == null) {
                                if (!opt.choiceOne) {
                                    opt.choice_rows = [];
                                }
                                loadData("", function (rows) {
                                    if (!opt.choiceOne) {
                                        $("#" + opt.pid + "_ok").linkbutton("enable");
                                    }
                                });
                            } else {
                                if (opt.choiceOne) {
                                    loadData(opt.valueMember + " = '" + opt.defaultValue + "'", function (rows) {
                                        if (!opt.choiceOne) {
                                            init_textbox(rows);
                                            $("#" + opt.pid + "_ok").linkbutton("enable");
                                        }
                                    });
                                } else {
                                    var w_where = "";
                                    var d_splits = opt.defaultValue.split(",");
                                    for (let i = 0; i < d_splits.length; i++) {
                                        w_where += (w_where == "" ? "" : ",") + "'" + d_splits[i] + "'";
                                    }
                                    loadData(opt.valueMember + " in (" + w_where + ")", function (rows) {
                                        if (!opt.choiceOne) {
                                            init_textbox(rows);
                                            $("#" + opt.pid + "_ok").linkbutton("enable");
                                        }
                                    });
                                }
                            }
                        });
                    });
                },
                onResize: function (width, height) {
                    if (!opt.onload) {
                        return;
                    }

                    opt.dg_.datagrid("resize", {
                        width: width - 12,
                        height: (!opt.choiceOne ? (height - 86) : (height - 56)),
                    });
                },
                onClose: function () {
                    try {
                        var $dg = opt.dg_.closest('div.datagrid');
                        $dg.remove();

                        $(this).dialog("destroy");
                        $(this).remove();
                        var pp = $(".panel-htop");
                        $(pp[pp.length - 1]).remove();
                    } catch (error) {
                        console.log(error);
                    }
                },
                modal: true,
                buttons: [
                    {
                        id: opt.pid + "_ok",
                        text: $.fn.yqUiExtText.btnOk,
                        iconCls: 'icon-ok',
                        handler: function () {
                            console.log("okokoko");
                            if (opt.choiceOne) {
                                var row = opt.dg_.datagrid("getSelected");
                                if (opt.callback) {
                                    opt.callback(row);
                                }
                            } else {
                                if (opt.callback) {
                                    opt.callback(opt.choice_rows);
                                }
                            }

                            $dg.dialog("close");
                        }
                    }, {
                        text: $.fn.yqUiExtText.btnNo,
                        iconCls: 'icon-no',
                        handler: function () {
                            $dg.dialog("close");
                        }
                    }]
            };

            dg_opt = $.yqPopPosition(dg_opt, opt);

            $dg.dialog(dg_opt);

            $("#" + opt.pid + "_ok").linkbutton("disable");
            //var $icon0 = $dg.dialog("getIcon", 0);
        }

        function init_textbox(choice_rows) {
            opt.textbox_.empty();
            opt.choice_rows = [];
            for (let i = 0; i < choice_rows.length; i++) {
                const item = choice_rows[i];
                init_textboxadd(item);
            }
        }

        function init_textboxadd(row) {
            opt.choice_rows.push(row);
            var $label = $('<span>' + row[opt.displayMember] + '<a></a></span>');
            opt.textbox_.append($label);
            $label.find("a").attr("val", row[opt.valueMember]);
            $label.find("a").bind("click", function () {
                var choice_rows_ = [];
                for (let j = 0; j < opt.choice_rows.length; j++) {
                    if (opt.choice_rows[j][opt.valueMember] != $(this).attr("val")) {
                        choice_rows_.push(opt.choice_rows[j]);
                    }
                }
                opt.choice_rows = choice_rows_;
                $(this).parent().remove();
            });
            $label.find("a").linkbutton({
                iconCls: 'icon-clear',
                plain: true
            });

        }

        function get_columns($object, callback) {
            if (opt.prevent_e.options.s_titles === undefined) {
                opt.prevent_e.options.s_titles = [];
            }

            if (opt.prevent_e.options.s_titles.length > 0) {
                var columns = $.yqDgColumns.call($object, opt.prevent_e.options.s_titles);
                callback(columns);
            } else {
                var pp_opt = {
                    ajaxUrl: opt.ajaxUrl,
                    dbname: opt.dbname,                //数据库
                    tbname: opt.tbname,                //表
                    tempno: opt.tempno
                };

                $.yqTbTitle(pp_opt, function (res) {
                    if (res.error == 0) {
                        opt.prevent_e.options.s_titles = $.yqFmUiTitle(res.titles);
                        var columns = $.yqDgColumns.call($object, opt.prevent_e.options.s_titles);
                        callback(columns);
                    }
                    else {
                        console.log(res);
                        callback([]);
                    }
                })
            }
        }

        function get_seektitle($object, callback) {
            if (opt.tempno == opt.seekNo) {
                get_columns($object, function (columns) {
                    callback(opt.prevent_e.options.s_titles);
                });
                return;
            }

            if (opt.prevent_e.options.q_titles === undefined) {
                opt.prevent_e.options.q_titles = [];
            }

            if (opt.prevent_e.options.q_titles.length > 0) {
                callback(opt.prevent_e.options.q_titles);
            } else {
                var pp_opt = {
                    ajaxUrl: opt.ajaxUrl,
                    dbname: opt.dbname,                //数据库
                    tbname: opt.tbname,                //表
                    tempno: opt.seekNo
                };

                $.yqTbTitle(pp_opt, function (res) {
                    if (res.error == 0) {
                        opt.prevent_e.options.q_titles = $.yqFmUiTitle(res.titles);
                        callback(opt.prevent_e.options.q_titles);
                    }
                    else {
                        console.log(res);
                        callback([]);
                    }
                })
            }
        }


        //加载数据
        function loadData(where, callback) {
            if (opt.running) {
                return;
            }

            $("#" + opt.pid + "_ok").linkbutton("disable");

            opt.running = true;
            if (where === null) {
                where = "";
            }
            opt.prewhere = opt.where;
            var l_where = where;
            if (!(opt.addWhere === null) && opt.addWhere != "") {
                if (l_where == "") {
                    l_where = opt.addWhere;
                } else {
                    l_where = "(" + l_where + ") and (" + opt.addWhere + ")";
                }
            }

            opt.dg_.datagrid("loading");

            if (opt.isPage) {
                $.yqDbTbPaging({
                    url: opt.ajaxUrl,
                    dbname: opt.dbname,
                    tbname: opt.tbname,
                    where: l_where,
                    order: opt.order,
                    pagesize: opt.pageSize,
                    pageno: opt.pageNo
                }, function (data) {
                    if (data.error == 0) {
                        toData(data);
                        if (typeof callback == "function") {
                            callback(data.rows);
                        }
                    }
                    else {
                        opt.running = false;
                        opt.dg_.datagrid("loaded");
                    }
                });
            }
            else {
                $.yqDbTbSelect({
                    url: opt.ajaxUrl,
                    dbname: opt.dbname,
                    tbname: opt.tbname,
                    where: l_where,
                    order: opt.order
                }, function (data) {
                    if (data.error == 0) {
                        toData(data);
                        if (typeof callback == "function") {
                            callback(data.rows);
                        }
                    }
                    else {
                        opt.running = false;
                        opt.dg_.datagrid("loaded");
                    }
                });
            }
        }

        function toData(data) {
            setForienKeys(data.rows,
                function () {
                    opt.dg_.datagrid("loadData", data);
                });
        }

        function setForienKeys(rows, callback) {
            var opts = {
                "ajaxUrl": opt.ajaxUrl,
                "rows": rows,
                "titles": opt.prevent_e.options.s_titles,
                "fk_rows": opt.prevent_e.options.fk_rows === undefined ? [] : opt.prevent_e.options.fk_rows
            };
            $.yqGetForeignkeys(opts,
                function (fk_rows) {
                    opt.prevent_e.options.fk_rows = fk_rows;
                    callback();
                });
        }
    },

    //文件代码编辑器
    yqFilePopEdit: function (opts) {
        var opt = $.extend({
            prevent_e: {
                clientX: 0,
                clientY: 0
            },
            mdiinfo: {
                clientX: 0,
                clientY: 0
            },
            verticalAlign: "none",
            width: 600,
            height: 420,
            horizontalAlign: "none",    //left,right,center,none
            verticalAlign: "none",      //top,bottom,center,none

            goDocEnd: false,
            data: null,
            isEdit: true,

            callback: function (row) {

            }
        }, opts);

        var $body;
        var $richbox;
        var $dg = $("<div></div>");

        $("body").append($dg);

        opt.onload = false;
        var dg_opt = {
            noheader: true,
            width: opt.width,
            height: opt.height,
            closed: false,
            cache: false,
            onOpen: function () {
                $body = $(this).dialog("body");
                var $div = $('<textarea style="width:100%;height:100%;"></textarea>');
                $div.attr("id", $.getUniqueID());
                $body.append($div);
                $div.css({ height: opt.height - 8, width: opt.width - 8 });
                opt.edit = $div;

                $div.yqFileEdit({
                    theme: "chrome",
                    fontSize: 14,
                    data: opt.data,
                    goDocEnd: opt.goDocEnd,
                    afterBindingTitle: function () {
                        var file_opt = $(this).yqFileEdit("options");
                        var $close_ = $('<a title="close"></a>');
                        file_opt.$title.find(".download").after($close_);
                        //$close_.before('<span class="easyui-linkbutton"></span>'); 
                        $close_.linkbutton({
                            iconCls: 'icon-clear',
                            plain: false,
                            disabled: false,
                            onClick: function () {
                                $dg.dialog("close");
                            }
                        });
                        $close_.css("margin-left", "8px");
                        //console.log(file_opt);

                        opt.onload = true;
                    }, //标题绑定后
                });
            },
            onResize: function (width, height) {
                if (!opt.onload) {
                    return;
                }

                opt.edit.yqFileEdit("resize", {
                    height: height - 14,
                    width: width - 14
                });
            },
            onClose: function () {
                opt.edit.yqFileEdit("destroy");
                $(this).dialog("destroy");
                $(this).remove();
            },
            modal: true,
        };

        dg_opt = $.yqPopPosition(dg_opt, opt);
        $dg.dialog(dg_opt);
    },

    //文件查看
    yqFilePopView: function (data) {
        var $dg = $("<div></div>");
        var w = $(window).width() * 0.9;
        var h = $(window).height() * 0.9;

        var view_opt = {
            title: data.name,
            width: w,
            height: h,
            closed: false,
            cache: false,
            modal: true,
            onOpen: function () {
                var $body = $(this).dialog("body");
                if (typeof data.sid == "string") {
                    var filevalue = $.getFileLink(data);
                    var $ifame = '<iframe src="' + filevalue + '" style="width:100%;height:' + (h - 44) + 'px;"></iframe>';
                    $body.append($ifame);
                } else if (typeof data.file == "object") {
                    var reader = new FileReader();
                    reader.readAsDataURL(data.file);
                    reader.onload = function () {
                        var $ifame = '<iframe src="' + reader.result + '" style="width:100%;height:' + (h - 44) + 'px;"></iframe>';
                        $body.append($ifame);
                    }
                }
            },
            onClose: function () {
                $(this).dialog("destroy");
            }
        };

        $dg.dialog(view_opt);
    },

    //--模板编辑器 开始-------------------------
    //uimaskedit 模板编辑 ui_type=900
    yqUiMaskPopEdit: function (opts) {
        var opt = $.extend({
            width: 600,
            height: 420,
            horizontalAlign: "none",    //left,right,center,none
            verticalAlign: "none",      //top,bottom,center,none
            ui_type: 2,
            value: {},
            isEdit: true,
            treeEdit: false,
            prevent_e: {         //调用组件信息
                id: "",
                options: {},  //调用组件jquery对象
                clientX: 0,
                clientY: 0
            },
            mdiinfo: {            //mdi窗体信息
                clientX: 0,
                clientY: 0
            },
        }, opts);

        var $body;
        var $dg = $("<div></div>");

        $("body").append($dg);

        var dg_opt = {
            title: opt.title,
            noheader: true,
            width: opt.width,
            height: opt.height,
            closed: false,
            cache: false,
            onOpen: function () {

                $body = $(this).dialog("body");
                $body.css({ "border-width": 0 });
                opt.$div = $("<div></div>")
                $body.append(opt.$div);

                opt.$div.attr("id", $.getUniqueID());

                var _opt = {
                    width: opt.width - 14,
                    height: opt.height - 56,
                    ui_type: opt.ui_type,
                    value: opt.value,
                    isEdit: opt.isEdit,
                    treeEdit: opt.treeEdit,
                }

                opt.$div.yqUiMaskEdit(_opt);
            },
            onResize: function (width, height) {
                opt.$div.yqUiMaskEdit("resize", {
                    width: width - 14,
                    height: height - 56,
                });
            },
            onClose: function () {
                opt.$div.yqUiMaskEdit("destroy");
                $(this).dialog("destroy");
                $(this).remove();
            },
            modal: true,

        };

        if (opt.isEdit) {
            dg_opt.buttons = [{
                text: $.fn.yqUiExtText.btnOk,
                iconCls: 'icon-ok',
                handler: function () {
                    var value = opt.$div.yqUiMaskEdit("getValue");
                    if (opt.prevent_e.options.beforeChange) {
                        opt.prevent_e.options.beforeChange.call($body, value,
                            function (tf, value2) {
                                if (!tf) {
                                    return;
                                }

                                if (opt.callback) {
                                    opt.callback(value2);
                                }
                                $dg.dialog("close");
                            })
                    }
                    else {
                        if (opt.callback) {
                            opt.callback(value);
                        }

                        $dg.dialog("close");
                    }
                }
            }, {
                text: $.fn.yqUiExtText.btnNo,
                iconCls: 'icon-no',
                handler: function () {
                    $dg.dialog("close");
                }
            }];
        }
        else {
            dg_opt.buttons = [{
                text: $.fn.yqUiExtText.btnClose,
                iconCls: 'icon-cancel',
                handler: function () {
                    $dg.dialog("close");
                }
            }];
        }

        dg_opt = $.yqPopPosition(dg_opt, opt);

        $dg.dialog(dg_opt);
    },

    //titles 模板编辑 ui_type=901
    yqTitlesEditPopEdit: function (opts) {
        var opt = $.extend({
            ajaxUrl: "/_db.html",
            title: "测试",
            width: 600,
            height: 420,
            horizontalAlign: "none",    //left,right,center,none
            verticalAlign: "none",      //top,bottom,center,none
            value: {
                titles: [],
                model: []
            },
            isEdit: true,
            prevent_e: {         //调用组件信息
                id: "",
                options: {},  //调用组件jquery对象
                clientX: 0,
                clientY: 0
            },
            mdiinfo: {            //mdi窗体信息
                clientX: 0,
                clientY: 0
            },
        }, opts);

        var $body;
        var $dg = $("<div></div>");

        $("body").append($dg);

        var dg_opt = {
            title: opt.title,
            noheader: true,
            width: opt.width,
            height: opt.height,
            closed: false,
            cache: false,
            onOpen: function () {
                $body = $(this).dialog("body");
                $body.css({ "border-width": 0, "overflow": "hidden" });

                $body.attr("id", $.getUniqueID());

                var _opt = {
                    ajaxUrl: opt.ajaxUrl,
                    width: opt.width - 14,
                    height: opt.height - 56,
                    value: opt.value,
                    isEdit: opt.isEdit
                }
                if (!(opt.dbname === undefined ||
                    opt.dbname === null ||
                    opt.dbname == "")) {
                    _opts.dbname = opt.dbname;
                }

                $body.yqTitlesEdit(_opt);
            },
            onResize: function (width, height) {
                $body.yqTitlesEdit("resize", {
                    width: width - 14,
                    height: height - 56,
                });
            },
            onClose: function () {
                $body.yqTitlesEdit("destroy");
                $(this).dialog("destroy");
                $(this).remove();
            },
            modal: true,

        };

        if (opt.isEdit) {
            dg_opt.buttons = [{
                text: $.fn.yqUiExtText.btnOk,
                iconCls: 'icon-ok',
                handler: function () {
                    var value = $body.yqTitlesEdit("getValue");

                    if (opt.prevent_e.options.beforeChange) {
                        opt.prevent_e.options.beforeChange.call($body, value,
                            function (tf, value2) {
                                if (!tf) {
                                    return;
                                }

                                if (opt.callback) {
                                    opt.callback(value2);
                                }
                                $dg.dialog("close");
                            })
                    }
                    else {
                        if (opt.callback) {
                            opt.callback(value);
                        }

                        $dg.dialog("close");
                    }
                }
            }, {
                text: $.fn.yqUiExtText.btnNo,
                iconCls: 'icon-no',
                handler: function () {
                    $dg.dialog("close");
                }
            }];
        }
        else {
            dg_opt.buttons = [{
                text: $.fn.yqUiExtText.btnClose,
                iconCls: 'icon-cancel',
                handler: function () {
                    $dg.dialog("close");
                }
            }];
        }

        dg_opt = $.yqPopPosition(dg_opt, opt);

        $dg.dialog(dg_opt);
    },

    //virtualedit 模板编辑 ui_type=902
    yqVirtualPopEdit: function (opts) {
        var opt = $.extend({
            width: 600,
            height: 420,
            horizontalAlign: "none",    //left,right,center,none
            verticalAlign: "none",      //top,bottom,center,none
            ui_type: 15,
            ui_mask: {},
            param: {
                titles: [],
                model: []
            },
            isEdit: true,
            prevent_e: {         //调用组件信息
                id: "",
                options: {},  //调用组件jquery对象
                clientX: 0,
                clientY: 0
            },
            mdiinfo: {            //mdi窗体信息
                clientX: 0,
                clientY: 0
            },
        }, opts);

        var $body;
        var $dg = $("<div></div>");

        $("body").append($dg);

        var dg_opt = {
            title: opt.title,
            noheader: true,
            width: opt.width,
            height: opt.height,
            closed: false,
            cache: false,
            onOpen: function () {
                $body = $(this).dialog("body");
                $body.css({ "border-width": 0, "overflow": "hidden" });
                opt.$div = $("<div></div>")
                $body.append(opt.$div);

                opt.$div.attr("id", $.getUniqueID());

                var _opt = {
                    width: opt.width - 11,
                    height: opt.height - 56,
                    ui_type: opt.ui_type,
                    ui_mask: opt.ui_mask,
                    param: opt.param,
                    isEdit: opt.isEdit,
                    treeEdit: opt.treeEdit,
                }

                opt.$div.yqVirtualEdit(_opt);
            },
            onResize: function (width, height) {
                opt.$div.yqVirtualEdit("resize", {
                    width: width - 11,
                    height: height - 56,
                });
            },
            onClose: function () {
                opt.$div.yqVirtualEdit("destroy");
                $(this).dialog("destroy");
                $(this).remove();
            },
            modal: true,

        };

        if (opt.isEdit) {
            dg_opt.buttons = [{
                text: $.fn.yqUiExtText.btnOk,
                iconCls: 'icon-ok',
                handler: function () {
                    var value = opt.$div.yqVirtualEdit("getValue");
                    if (opt.prevent_e.options.beforeChange) {
                        opt.prevent_e.options.beforeChange.call($body, value,
                            function (tf, value2) {
                                if (!tf) {
                                    return;
                                }

                                if (opt.callback) {
                                    opt.callback(value2);
                                }
                                $dg.dialog("close");
                            })
                    }
                    else {
                        if (opt.callback) {
                            opt.callback(value);
                        }

                        $dg.dialog("close");
                    }
                }
            }, {
                text: $.fn.yqUiExtText.btnNo,
                iconCls: 'icon-no',
                handler: function () {
                    $dg.dialog("close");
                }
            }];
        }
        else {
            dg_opt.buttons = [{
                text: $.fn.yqUiExtText.btnClose,
                iconCls: 'icon-cancel',
                handler: function () {
                    $dg.dialog("close");
                }
            }];
        }

        dg_opt = $.yqPopPosition(dg_opt, opt);

        $dg.dialog(dg_opt);
    },

    //虚表联合编辑器  ui_type=999
    yqUnitPopEdit: function (opts) {
        var opt = $.extend({
            prevent_e: {         //调用组件信息
                id: "",
                options: {},  //调用组件jquery对象
                clientX: 0,
                clientY: 0
            },
            mdiinfo: {            //mdi窗体信息
                clientX: 0,
                clientY: 0
            },
            width: 600,
            height: 420,
            horizontalAlign: "none",    //left,right,center,none
            verticalAlign: "none",      //top,bottom,center,none

            ajaxUrl: "/_db.html",
            ui_mask: {
                ui_type: 17,  //17-attr,15-table,16-trees
                titles: {
                    titles: [{
                        is_func: false,
                        name: "code",
                        ui_title: "Code",
                        ui_type: 2,
                        ui_width: 80,
                        ui_visible: true,
                        ui_readonly: false,
                        ui_mask: {}
                    }, {
                        is_func: false,
                        name: "name",
                        ui_title: "Name",
                        ui_type: 2,
                        ui_width: 80,
                        ui_visible: true,
                        ui_readonly: false,
                        ui_mask: {}
                    }]
                }
            },  //数据列配置对象
            data: {},
            isEdit: true,
        }, opts);

        var $body;
        var $dg = $("<div></div>");

        $("body").append($dg);

        var dg_opt = {
            title: opt.title,
            noheader: true,
            width: opt.width,
            height: opt.height,
            closed: false,
            cache: false,
            onOpen: function () {
                $body = $(this).dialog("body");
                $body.css({ "border-width": 0, "overflow": "hidden" });
                opt.$div = $("<div></div>")
                $body.append(opt.$div);
                opt.$div.attr("id", $.getUniqueID());

                var _opt = {
                    width: opt.width - 11,
                    height: opt.height - 56,
                    ajaxUrl: opt.ajaxUrl,
                    ui_mask: opt.ui_mask,
                    data: opt.data,
                    isEdit: opt.isEdit,
                }

                opt.$div.yqUnitEdit(_opt);
            },
            onResize: function (width, height) {
                opt.$div.yqUnitEdit("resize", {
                    width: width - 11,
                    height: height - 56,
                });
            },
            onClose: function () {
                opt.$div.yqUnitEdit("destroy");
                $(this).dialog("destroy");
                $(this).remove();
            },
            modal: true,

        };

        if (opt.isEdit) {
            dg_opt.buttons = [{
                text: $.fn.yqUiExtText.btnOk,
                iconCls: 'icon-ok',
                handler: function () {
                    var value = opt.$div.yqUnitEdit("getData");
                    if (opt.prevent_e.options.beforeChange) {
                        opt.prevent_e.options.beforeChange.call($body, value,
                            function (tf, value2) {
                                if (!tf) {
                                    return;
                                }

                                if (opt.callback) {
                                    opt.callback(value2);
                                }
                                $dg.dialog("close");
                            })
                    }
                    else {
                        if (opt.callback) {
                            opt.callback(value);
                        }

                        $dg.dialog("close");
                    }
                }
            }, {
                text: $.fn.yqUiExtText.btnNo,
                iconCls: 'icon-no',
                handler: function () {
                    $dg.dialog("close");
                }
            }];
        }
        else {
            dg_opt.buttons = [{
                text: $.fn.yqUiExtText.btnClose,
                iconCls: 'icon-cancel',
                handler: function () {
                    $dg.dialog("close");
                }
            }];
        }

        dg_opt = $.yqPopPosition(dg_opt, opt);

        $dg.dialog(dg_opt);
    },
    //--模板编辑器 结束-------------------------
});

//格式化相关
jQuery.extend({
    ///<summary>获得字符串实际长度，中文2，英文1</summary>
    ///<param name="str">要获得长度的字符串</param>
    yqGetStrLen: function (str) {
        if (str === undefined || str === null) {
            return 0;
        }

        var realLength = 0, len = str.length, charCode = -1;
        for (var i = 0; i < len; i++) {
            charCode = str.charCodeAt(i);
            if (charCode >= 0 && charCode <= 128) realLength += 1;
            else realLength += 2;
        }
        return realLength;
    },

    yqToString: function (val) {
        var t = typeof val;
        if (t == "undefined" || val === null) {
            return null;
        }
        v = null;
        if (t == "string") {
            v = val;
        } else {
            v = val.toString();
        }
        if (val == "") {
            val = null;
        }
        return v;
    },

    yqToBoolean: function (val) {
        if (typeof val === 'boolean') {
            return val;
        }
        if (typeof val === 'string') {
            return val.toLowerCase() === 'true' ||
                val === '1' ||
                val.toLowerCase() === 'yes' ||
                val.toLowerCase() === 'on';
        }
        if (typeof val === 'number') {
            return val !== 0;
        }
        if (val === null || val === undefined) {
            return false;
        }
        if (Array.isArray(val)) {
            return val.length > 0;
        }
        if (typeof val === 'object') {
            return Object.keys(val).length > 0;
        }
        return !!val;
    },

    yqToInt: function (val) {
        var t = typeof val;
        if (t == "undefined" || val === null) {
            return null;
        }

        val = parseInt(val);
        if (isNaN(val)) {
            val = null;
        }
        return val;
    },

    yqToNumber: function (val) {
        var t = typeof val;
        if (t == "undefined" || val === null) {
            return null;
        }

        val = Number(val);
        if (isNaN(val)) {
            val = null;
        }
        return val;
    },

    //日期格式化（不带时间）  "format": "yyyy-MM-dd hh:mm:ss"
    formatterdatebox: function (value, format) {
        try {
            if (value == "" || value === null || value === undefined)
                return "";

            var utcCurrTime;
            if (typeof (value) != "object") {
                utcCurrTime = $.convert_todate(value);
            }
            else {
                utcCurrTime = value;
            }

            if (format === undefined || format === null) {
                format = "yyyy/MM/dd";
            }

            //console.log(utcCurrTime);

            return utcCurrTime.Format(format);
        } catch (Error) {
            console.log("formatterdatebox:" + Error);
            console.log(value, format);
            return ""
        }
    },
    //日期格式化（带时间）
    formatterdatetimebox: function (value, format) {
        try {
            if (value == "" || value === null || value === undefined)
                return "";

            var utcCurrTime;
            if (typeof (value) != "object") {
                utcCurrTime = $.convert_todate(value);
            }
            else {
                utcCurrTime = value;
            }

            if (format === undefined || format === null) {
                format = "yyyy/MM/dd hh:ss";
            }
            format = format.replace("HH", "hh");
            //console.log(format);
            return utcCurrTime.Format(format);
        } catch (Error) {
            console.log("formatterdatetimebox:" + Error);
            console.log(value, format);
            return ""
        }
    },
    //时间格式化（不带日期）
    formattertimespinner: function (value, format) {
        try {
            if (value == "" || value === null || value === undefined)
                return "";

            var utcCurrTime;

            if (typeof (value) != "object") {
                utcCurrTime = $.convert_todate(value);
            }
            else {
                utcCurrTime = value;
            }

            if (format === undefined || format === null) {
                format = "hh:ss";
            }
            format = format.replace("HH", "hh");
            //console.log("formattertimespinner", value);
            //console.log(utcCurrTime, format);
            return utcCurrTime.Format(format);
        } catch (Error) {
            console.log("formattertimespinner:" + Error);
            console.log(value, format);
            return ""
        }
    },
    //Date字符转日期类型
    convert_todate: function (value) {
        try {
            if (value === null)
                return null;

            if (value instanceof Date || typeof value == "object") {
                return value;
            }

            var str = value;
            if (str.indexOf("/Date(") != -1) {
                var date = new Date();
                var str1 = str.replace("/Date(", "");
                var str2 = str1.replace(")/", "");
                var dd = parseInt(str2);
                date.setTime(dd);

                return date;
            } else {
                str = str.replace(/-/g, "/");

                str = str.replace('年', "/");
                str = str.replace('月', "/");

                str = str.replace('T', " ");

                if (str.indexOf("/") == -1) {
                    str = "2000/01/01 " + str;
                }

                var t = Date.parse(str);
                if (!isNaN(t)) {
                    date = new Date(t);
                } else {
                    date = null;
                }
            }


            //console.log(str, date);
            return date;

        } catch (Error) {
            console.log('function jsontodate(' + value + ')', Error)
            return null;
        }
    },

    // 输出: "2025-10-19T15:30:00+08:00"
    formatDateToRFC3339: function (date) {
        date = $.convert_todate(date);
        if (date === null) {
            return null;
        }
        // 获取时区偏移（分钟）
        const timezoneOffset = date.getTimezoneOffset();
        const timezoneOffsetHours = Math.abs(Math.floor(timezoneOffset / 60));
        const timezoneOffsetMinutes = Math.abs(timezoneOffset % 60);
        const timezoneSign = timezoneOffset <= 0 ? '+' : '-';

        // 格式化为 YYYY-MM-DDTHH:mm:ss+HH:mm
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, '0');
        const day = String(date.getDate()).padStart(2, '0');
        const hours = String(date.getHours()).padStart(2, '0');
        const minutes = String(date.getMinutes()).padStart(2, '0');
        const seconds = String(date.getSeconds()).padStart(2, '0');
        return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}${timezoneSign}${String(timezoneOffsetHours).padStart(2, '0')}:${String(timezoneOffsetMinutes).padStart(2, '0')}`;
    },

    //带小数数值格式化列表显示
    formatternumberbox: function (value, format) {
        try {
            if (value === undefined || value === null || String(value) == "") {
                return "";
            } else {
                if (format === undefined) {
                    format = {};
                }

                var dd = Number(value);
                if (isNaN(dd)) {
                    return null;
                }
                if (format.precision != null) {
                    dd = dd.toFixed(format.precision);
                }

                if (format.groupSeparator != null) {
                    dd = $.thousandBitSeparator(dd, format.groupSeparator)
                }
                return dd;
            }
        } catch (Error) {
            console.log(format);
            console.log("formatternumberboxview:" + Error);
            return null;
        }


    },
    //整数格式化
    formatternumberspinner: function (value, format) {
        try {
            if (value === undefined || value === null || String(value) == "") {
                return "";
            } else {
                if (format === undefined) {
                    format = {};
                }

                var dd = parseInt(value);
                if (isNaN(dd)) {
                    return "";
                }

                if (format.groupSeparator != null) {
                    dd = $.thousandBitSeparator(dd, format.groupSeparator)
                }

                return dd.toString();
            }
        } catch (Error) {
            console.log("formatternumberspinner:" + Error);
            console.log(value);
            return "";
        }
    },
    /* 
      取得外键或树形结构显示信息
      var row ={"name":"name1","code":"code1","no":1234}
      var  displayMember = "{name}[{code}]-{no}";
    */
    getDisplayValue: function (row, displayMember) {
        if (row == null) {
            return null;
        }

        var n_val = "";

        try {

            var regex = /\{(.+?)\}/g; // {} 花括号，大括号
            var regexvals = displayMember.match(regex);
            //console.log(regexvals);
            if (regexvals === null) {
                n_val = row[displayMember];
            } else {
                var str = displayMember;
                for (var i = 0; i < regexvals.length; i++) {
                    var field = regexvals[i].substring(1, regexvals[i].length - 1);
                    var val = row[field];
                    if (val === undefined) {
                        val = "";
                    }
                    str = str.replace(regexvals[i], val);
                }

                n_val = str;
            }
        } catch (error) {
            console.log("$.getDisplayValue", error);
            console.log("row=", row);
            console.log("displayMember=", displayMember);
        }

        return n_val;
    },
    //取得文件连接
    getFileLink: function (data) {
        var filevalue;
        if (data.sto_type == 1) {
            filevalue = "!" + data.sto_name + "_" + data.sid;
        } else if (data.sto_type == 2) {
            filevalue = "@" + data.sto_name + "_" + data.sid;
        }
        return filevalue;
    },

    //var obj1 = {id:1,name:"张三"}
    // var obj2 = {id:2,name:"李四"}
    // var obj3 = {id:1,name:"张三"}
    // console.log(isObjEqual(obj1,obj2));//false
    // console.log(isObjEqual(obj1,obj3));//true
    isRowEqual: function (o1, o2) {   //比较两个行数据是否相同
        var props1 = Object.getOwnPropertyNames(o1);
        var props2 = Object.getOwnPropertyNames(o2);
        if (props1.length != props2.length) {
            return false;
        }
        for (var i = 0, max = props1.length; i < max; i++) {
            var propName = props1[i];
            var a = o1[propName];
            var b = o2[propName];
            var tf = $.isObjEqual(a, b);
            if (!tf) {
                return false;
            }
        }
        return true;
    },
    isObjEqual: function (a, b) {   //比较两个值数据是否相同
        if (a == "") {
            a = null;
        }
        if (b == "") {
            b = null;
        }

        if (a instanceof Date && b instanceof Date) {
            if (a.getTime() != b.getTime()) {
                return false;
            }
        }
        else if (a !== b) {
            return false;
        }

        return true;
    },
    //数字千分位分隔符处理
    thousandBitSeparator: function (num, groupSeparator) {
        return num && (num
            .toString().indexOf('.') != -1 ? num.toString().replace(/(\d)(?=(\d{3})+\.)/g, function ($1, $2) {
                return $2 + groupSeparator;
            }) : num.toString().replace(/(\d)(?=(\d{3})+\b)/g, function ($1, $2) {
                return $2 + groupSeparator;
            }));
    },
});

//扩展 页面参数获取
jQuery.extend({
    //获取位置 client位置
    getPreventDefault: function (e) {
        var event = $(e)[0];
        if (event === undefined) {
            return {
                clientX: 0,
                clientY: 0,
                $object: e,
            }
        }

        var X;
        var Y;
        try {
            if (window.top != window.self) {
                X = event.getBoundingClientRect().left;
                Y = event.getBoundingClientRect().top;
            } else {
                X = event.getBoundingClientRect().left + document.documentElement.scrollLeft;
                Y = event.getBoundingClientRect().top + document.documentElement.scrollTop;
            }
        } catch (err) {
            console.error(err);
        }

        return {
            clientX: X,
            clientY: Y + event.clientHeight + 1,
            $object: e,
        }
    },
    //mdi窗体参数
    yqGetWindParams: function () { // 不传name返回所有值，否则返回对应值
        var self_width = 0;
        var self_height = 0;
        var clientX = 0;
        var clientY = 0;
        var target = window;

        if (window.top != window.self) {
            var iframenum = null;
            var url = window.location.search;
            if (url.indexOf('?') == 0) {
                url = url.substring(1);
                url = url.split('&');
                // 获取全部参数及其值
                for (var i = 0; i < url.length; i++) {
                    var info = url[i].split('=');
                    if (info[0] == "iframenum") {
                        iframenum = decodeURI(info[1]);
                    }
                }
            }

            if (!(iframenum === null)) {
                target = window.parent;

                var $form = $(window.parent.document).find("#iframe_" + iframenum);
                clientX = $form[0].getBoundingClientRect().left;
                clientY = $form[0].getBoundingClientRect().top;

                self_width = $form.width();
                self_height = $form.height();
            }
        }

        if (typeof self_width === "string") {
            self_width = parseInt(self_width.replace("px", ""));
        }
        if (typeof self_height === "string") {
            self_height = parseInt(self_height.replace("px", ""));
        }

        return {
            "target": window.top,
            "clientX": clientX,     //frame子窗体mid窗体中的位置（左上角位置）
            "clientY": clientY,     //
            "self_width": self_width,   //frame窗体的宽度
            "self_height": self_height  //frame窗体的高度
        };
    },
    //通过单元格对象获取datagrid参数
    yqGetDataGridByCell: function (el) {
        return {
            target: getTarget(el),
            field: getField(el),
            rowindex: getRowIndex(el)
        };

        function getTarget(el) {
            //oceandeng 兼容处理bug
            var target = $(el).closest('div.datagrid-view');
            if (target.children('table').length > 0) {
                return target.children('table');
            }
            else {
                return target.children(".datagrid-f");
            }
        }

        function getField(el) {
            var target = $(el).closest('div.datagrid-cell');
            return target.closest("td").attr("field");
        }

        function getRowIndex(el) {
            var target = $(el).closest('tr.datagrid-row');
            return parseInt(target.attr("datagrid-row-index"));
        }
    },

    //在url弹出窗体内，获取父窗体调用组件参数信息
    yqWinPopEdit_Params: function () {
        var iframeid = "iframe_" + $.urlRequest("iframenum");
        return window.parent.$("#" + iframeid).data("prevent_e");
    }
});

Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substring(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
};

/*
 * 重写时间的toJSON方法，因为在调用JSON.stringify的时候，时间转换就调用的toJSON，这样会导致少8个小时，所以重写它的toJSON方法
 */
Date.prototype.toJSON = function () {
    try {
        var year = this.getFullYear(); // 获取年份
        var month = this.getMonth() + 1; // 获取月份
        var day = this.getDate(); // 获取日期
        var hours = this.getHours(); // 获取小时
        var minutes = this.getMinutes(); // 获取分钟
        var seconds = this.getSeconds(); // 获取秒数
        var milliseconds = this.getMilliseconds(); // 获取毫秒数

        // 格式化为 yyyy-MM-dd hh:mm:ss.M+08 格式
        var endDate = year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day) + ' ' +
            (hours < 10 ? '0' + hours : hours) + ':' + (minutes < 10 ? '0' + minutes : minutes) + ':' +
            (seconds < 10 ? '0' + seconds : seconds) + "." + milliseconds;

        var offset = (new Date().getTimezoneOffset()) / 60;
        if (offset >= 0) {
            if (offset < 10) {
                offset = "0" + offset;
            }
            offset = "-" + offset;
        } else {
            offset = 0 - offset;
            if (offset < 10) {
                offset = "0" + offset;
            }
            offset = "+" + offset;
        }

        //endDate = endDate.replace(/\s+/g, "T") + "+" + offset + ":00";
        endDate += offset + ":00";
        return endDate;
    }
    catch (err) {
        return this.toISOString();
    }
}